@nestia/core 0.1.5 → 0.1.7
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.
- package/LICENSE +1 -1
- package/README.md +336 -0
- package/lib/decorators/PlainBody.d.ts +1 -1
- package/lib/decorators/PlainBody.js +1 -1
- package/lib/executable/core.d.ts +2 -0
- package/lib/executable/core.js +100 -0
- package/lib/executable/core.js.map +1 -0
- package/lib/executable/internal/CommandParser.d.ts +3 -0
- package/lib/executable/internal/CommandParser.js +21 -0
- package/lib/executable/internal/CommandParser.js.map +1 -0
- package/lib/executable/internal/CoreSetupWizard.d.ts +4 -0
- package/lib/executable/internal/CoreSetupWizard.js +259 -0
- package/lib/executable/internal/CoreSetupWizard.js.map +1 -0
- package/package.json +5 -1
- package/src/decorators/EncryptedBody.ts +102 -102
- package/src/decorators/EncryptedController.ts +43 -43
- package/src/decorators/EncryptedModule.ts +77 -77
- package/src/decorators/EncryptedRoute.ts +203 -203
- package/src/decorators/PlainBody.ts +38 -38
- package/src/decorators/TypedBody.ts +49 -49
- package/src/decorators/TypedParam.ts +70 -70
- package/src/decorators/TypedRoute.ts +149 -149
- package/src/decorators/internal/EncryptedConstant.ts +4 -4
- package/src/decorators/internal/get_path_and_stringify.ts +77 -77
- package/src/decorators/internal/headers_to_object.ts +10 -10
- package/src/decorators/internal/route_error.ts +38 -38
- package/src/decorators/internal/validate_request_body.ts +59 -59
- package/src/executable/core.ts +46 -0
- package/src/executable/internal/CommandParser.ts +15 -0
- package/src/executable/internal/CoreSetupWizard.ts +177 -0
- package/src/index.ts +5 -5
- package/src/module.ts +11 -11
- package/src/options/INestiaTransformOptions.ts +6 -6
- package/src/options/INestiaTransformProject.ts +7 -7
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IResponseBodyStringifier.ts +25 -25
- package/src/transform.ts +20 -20
- package/src/transformers/BodyTransformer.ts +106 -106
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/MethodTransformer.ts +91 -91
- package/src/transformers/NodeTransformer.ts +18 -18
- package/src/transformers/ParameterTransformer.ts +45 -45
- package/src/transformers/RouteTransformer.ts +131 -131
- package/src/typings/Creator.ts +3 -3
- package/src/utils/ExceptionManager.ts +126 -126
- package/src/utils/Singleton.ts +20 -20
package/LICENSE
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
# Nestia Core
|
|
2
|
+
[](https://github.com/samchon/nestia/blob/master/LICENSE)
|
|
3
|
+
[](https://www.npmjs.com/package/@nestia/core)
|
|
4
|
+
[](https://www.npmjs.com/package/@nestia/core)
|
|
5
|
+
[](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)
|
|
6
|
+
[](https://github.com/samchon/nestia/wiki)
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npx nestia setup
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Super-easy and super-fast validator decorators for NestJS.
|
|
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.
|
|
15
|
+
|
|
16
|
+
Furthremore, `@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.
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { Controller } from "@nestjs/common";
|
|
20
|
+
import { TypedBody, TypedRoute } from "@nestia/core";
|
|
21
|
+
|
|
22
|
+
import { IBbsArticle } from "@bbs-api/structures/IBbsArticle";
|
|
23
|
+
|
|
24
|
+
@Controller("bbs/articles")
|
|
25
|
+
export class BbsArticlesController {
|
|
26
|
+
/**
|
|
27
|
+
* `TypedRoute.Post()`: safe `JSON.stringify()` with type validation.
|
|
28
|
+
*
|
|
29
|
+
* Furthermore, its 10x times faster than native `JSON.stringify()` function.
|
|
30
|
+
*/
|
|
31
|
+
@TypedRoute.Post()
|
|
32
|
+
public async store(
|
|
33
|
+
/**
|
|
34
|
+
* Super-fast request body validator through `TypedBody()`.
|
|
35
|
+
*
|
|
36
|
+
* It also requires only one line.
|
|
37
|
+
*/
|
|
38
|
+
@TypedBody() input: IBbsArticle.IStore
|
|
39
|
+
): Promise<IBbsArticle>;
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
/**
|
|
45
|
+
* You don't need any extra dedication like:
|
|
46
|
+
*
|
|
47
|
+
* - `@nestjs/swagger`: JSON schema definition
|
|
48
|
+
* - `class-transformer`: class definition with decorator function class
|
|
49
|
+
*
|
|
50
|
+
* Just enjoy the pure interface type as DTO
|
|
51
|
+
*/
|
|
52
|
+
export interface IBbsArticle {
|
|
53
|
+
/**
|
|
54
|
+
* @format uuid
|
|
55
|
+
*/
|
|
56
|
+
id: string;
|
|
57
|
+
writer: string;
|
|
58
|
+
title: string;
|
|
59
|
+
content: string;
|
|
60
|
+
created_at: string;
|
|
61
|
+
}
|
|
62
|
+
export namespace IBbsArticle {
|
|
63
|
+
export interface IStore {
|
|
64
|
+
writer: string;
|
|
65
|
+
title: string;
|
|
66
|
+
content: string;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
%20Core(TM)%20i5-1135G7%20%40%202.40GHz/images/is.svg)
|
|
72
|
+
|
|
73
|
+
> 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)
|
|
74
|
+
>
|
|
75
|
+
> `@nestia/core` is providing super-easy and super-fast validator by wrapping [typia](https://github.com/samchon/typia)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## Setup
|
|
82
|
+
### Setup Wizard
|
|
83
|
+
```bash
|
|
84
|
+
# setup both @nestia/core and @nestia/sdk
|
|
85
|
+
npx nestia setup
|
|
86
|
+
|
|
87
|
+
# setup @nestia/core only
|
|
88
|
+
npx nestia setup
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
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.
|
|
92
|
+
|
|
93
|
+
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:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx ttsc
|
|
97
|
+
npx ts-node -C ttypescript src/index.ts
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
> 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).
|
|
101
|
+
>
|
|
102
|
+
> ```bash
|
|
103
|
+
> npx nestia setup \
|
|
104
|
+
> --compiler (ttypescript|ts-patch)
|
|
105
|
+
> --module (npm|pnpm|yarn)
|
|
106
|
+
>
|
|
107
|
+
> npx nestia setup
|
|
108
|
+
> npx nestia setup --module yarn
|
|
109
|
+
> npx nestia setup --compiler ts-patch
|
|
110
|
+
> ```
|
|
111
|
+
|
|
112
|
+
### NPM Packages
|
|
113
|
+
If you want to install and configure manually, install `@nestia/core` module first.
|
|
114
|
+
|
|
115
|
+
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`.
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm install --save @nestia/core
|
|
119
|
+
|
|
120
|
+
# ENSURE THOSE PACKAGES ARE INSTALLED
|
|
121
|
+
npm install --save-dev typescript
|
|
122
|
+
npm install --save-dev ttypescript
|
|
123
|
+
npm install --save-dev ts-node
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### `tsconfig.json`
|
|
127
|
+
After the installation, you've to configure `tsconfig.json` file like below.
|
|
128
|
+
|
|
129
|
+
Add a property transform and its value as `@nestia/core/lib/transform` into `compilerOptions.plugins` array. Also, do same thing on `typia/lib/transform` value. When configuring, I recommend you to use the strict option, to enforce developers to distinguish whether each property is nullable or undefindable.
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"compilerOptions": {
|
|
134
|
+
"strict": true,
|
|
135
|
+
"plugins": [
|
|
136
|
+
{
|
|
137
|
+
"transform": "@nestia/core/lib/transform",
|
|
138
|
+
// "validate": "assert", // "assert" | "is" | "validate"
|
|
139
|
+
// "stringify": "is", // null | "stringify" | "assert" | "is" | "validate"
|
|
140
|
+
},
|
|
141
|
+
{ "transform": "typia/lib/transform" }
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Also, you can configure additional properties like `validate` and `stringify`.
|
|
148
|
+
|
|
149
|
+
Through the `validate` property, you can specialize which validation algorithm of [typia](https://github.com/samchon/typia) to be used. Default is `assert` function and if you choose `is` function instead, the validation speed would be extremely faster, but any reason why would be provided when wrong typed data comes. Otherwise you select `validate` function, its validation speed would be slower, but most detailed reasons would be provided.
|
|
150
|
+
|
|
151
|
+
By specializing `stringify` property, you can specialize which JSON stringify function of [typia](https://github.com/samchon/typia) would be used. Default is `assert`, but if choose `null` instead, it would be replaced to `JSON.stringify()` function. Otherwise you configure it as `stringify`, fastest logic would be used, but unexpected behavior would be happend when wrong typed data comes.
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
// RUNTIME VALIDATORS
|
|
155
|
+
export function is<T>(input: unknown | T): boolean; // returns boolean
|
|
156
|
+
export function assert<T>(input: unknown | T): T; // throws TypeGuardError
|
|
157
|
+
export function validate<T>(input: unknown | T): IValidation<T>; // detailed
|
|
158
|
+
|
|
159
|
+
// FAST STRINGIFY FUNCTIONS
|
|
160
|
+
export function stringify<T>(input: T): string; // unsafe, but very fast
|
|
161
|
+
export function assertStringify<T>(input: T): string; // assert + stringify
|
|
162
|
+
export function isStringify<T>(input: T): string | null; // is + stringify
|
|
163
|
+
export function validateStringify<T>(input: T): IValidation<T>; // validate +
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
## Features
|
|
170
|
+
```typescript
|
|
171
|
+
import { Controller } from "@nestjs/common";
|
|
172
|
+
import { TypedBody, TypedRoute } from "@nestia/core";
|
|
173
|
+
|
|
174
|
+
import { IBbsArticle } from "@bbs-api/structures/IBbsArticle";
|
|
175
|
+
|
|
176
|
+
@Controller("bbs/articles")
|
|
177
|
+
export class BbsArticlesController {
|
|
178
|
+
/**
|
|
179
|
+
* `TypedRoute.Post()`: safe `JSON.stringify()` with type validation.
|
|
180
|
+
*
|
|
181
|
+
* Furthermore, its 10x times faster than native `JSON.stringify()` function.
|
|
182
|
+
*/
|
|
183
|
+
@TypedRoute.Post()
|
|
184
|
+
public async store(
|
|
185
|
+
/**
|
|
186
|
+
* Super-fast request body validator through `TypedBody()`.
|
|
187
|
+
*
|
|
188
|
+
* It also requires only one line.
|
|
189
|
+
*/
|
|
190
|
+
@TypedBody() input: IBbsArticle.IStore
|
|
191
|
+
): Promise<IBbsArticle>;
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### TypedBody
|
|
196
|
+
`TypedBody` is a decorator function for `application/json` typed request body.
|
|
197
|
+
|
|
198
|
+
Also, it supports super-fast validation pipe, which is 15,000x times faster then ordinary `nest.Body()` decorator using `class-validator`.
|
|
199
|
+
|
|
200
|
+
### TypedRoute
|
|
201
|
+
`TypedRoute` is a decorator function for `application/json` typed reponse body.
|
|
202
|
+
|
|
203
|
+
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.
|
|
204
|
+
|
|
205
|
+
### Encryption
|
|
206
|
+
`@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.
|
|
207
|
+
|
|
208
|
+
- AES-128/256
|
|
209
|
+
- CBC mode
|
|
210
|
+
- PKCS #5 Padding
|
|
211
|
+
- Base64 Encoding
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
## Appendix
|
|
218
|
+
### Nestia SDK
|
|
219
|
+
```bash
|
|
220
|
+
npx nestia swagger
|
|
221
|
+
npx nestia sdk
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
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.
|
|
225
|
+
|
|
226
|
+
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:
|
|
227
|
+
|
|
228
|
+
#### `BbsArticlesController.ts`
|
|
229
|
+
```typescript
|
|
230
|
+
import { Controller } from "@nestjs/common";
|
|
231
|
+
import { TypedBody, TypedRoute } from "@nestia/core";
|
|
232
|
+
|
|
233
|
+
import { IBbsArticle } from "@bbs-api/structures/IBbsArticle";
|
|
234
|
+
|
|
235
|
+
@Controller("bbs/articles")
|
|
236
|
+
export class BbsArticlesController {
|
|
237
|
+
/**
|
|
238
|
+
* `TypedRoute.Post()`: safe `JSON.stringify()` with type validation.
|
|
239
|
+
*
|
|
240
|
+
* Furthermore, its 10x times faster than native `JSON.stringify()` function.
|
|
241
|
+
*/
|
|
242
|
+
@TypedRoute.Post()
|
|
243
|
+
public async store(
|
|
244
|
+
/**
|
|
245
|
+
* Super-fast request body validator through `TypedBody()`.
|
|
246
|
+
*
|
|
247
|
+
* It also requires only one line.
|
|
248
|
+
*/
|
|
249
|
+
@TypedBody() input: IBbsArticle.IStore
|
|
250
|
+
): Promise<IBbsArticle>;
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### `src/functional/bbs/articles/index.ts`
|
|
255
|
+
```typescript
|
|
256
|
+
import { Fetcher, IConnection } from "@nestia/fetcher";
|
|
257
|
+
import { IBbsArticle } from "../../../structures/IBbsArticle";
|
|
258
|
+
|
|
259
|
+
export function store(
|
|
260
|
+
connection: api.IConnection,
|
|
261
|
+
input: IBbsArticle.IStore
|
|
262
|
+
): Promise<IBbsArticle> {
|
|
263
|
+
return Fetcher.fetch(
|
|
264
|
+
connection,
|
|
265
|
+
store.ENCRYPTED,
|
|
266
|
+
store.METHOD,
|
|
267
|
+
store.path(),
|
|
268
|
+
input
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
export namespace store {
|
|
272
|
+
export const METHOD = "POST" as const;
|
|
273
|
+
export function path(): string {
|
|
274
|
+
return "/bbs/articles";
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
#### SDK utilization code
|
|
280
|
+
```typescript
|
|
281
|
+
import api from "@bbs-api";
|
|
282
|
+
import typia from "typia";
|
|
283
|
+
|
|
284
|
+
export async function test_bbs_article_store(connection: api.IConnection) {
|
|
285
|
+
const article: IBbsArticle = await api.functional.bbs.articles.store(
|
|
286
|
+
connection,
|
|
287
|
+
{
|
|
288
|
+
name: "John Doe",
|
|
289
|
+
title: "some title",
|
|
290
|
+
content: "some content",
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
typia.assert(article);
|
|
294
|
+
console.log(article);
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Typia
|
|
299
|
+
> https://github.com/samchon/typia
|
|
300
|
+
>
|
|
301
|
+
> `@nestia/core` is wrapping `typia` and the `typia` is:
|
|
302
|
+
|
|
303
|
+
[](https://github.com/samchon/typia/blob/master/LICENSE)
|
|
304
|
+
[](https://www.npmjs.com/package/typia)
|
|
305
|
+
[](https://www.npmjs.com/package/typia)
|
|
306
|
+
[](https://github.com/samchon/typia/actions?query=workflow%3Abuild)
|
|
307
|
+
[](https://github.com/samchon/typia/wiki)
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
// RUNTIME VALIDATORS
|
|
311
|
+
export function is<T>(input: unknown | T): input is T; // returns boolean
|
|
312
|
+
export function assert<T>(input: unknown | T): T; // throws TypeGuardError
|
|
313
|
+
export function validate<T>(input: unknown | T): IValidation<T>; // detailed
|
|
314
|
+
|
|
315
|
+
// STRICT VALIDATORS
|
|
316
|
+
export function equals<T>(input: unknown | T): input is T;
|
|
317
|
+
export function assertEquals<T>(input: unknown | T): T;
|
|
318
|
+
export function validateEquals<T>(input: unknown | T): IValidation<T>;
|
|
319
|
+
|
|
320
|
+
// JSON
|
|
321
|
+
export function application<T>(): IJsonApplication; // JSON schema
|
|
322
|
+
export function assertParse<T>(input: string): T; // type safe parser
|
|
323
|
+
export function assertStringify<T>(input: T): string; // safe and faster
|
|
324
|
+
// +) isParse, validateParse
|
|
325
|
+
// +) stringify, isStringify, validateStringify
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
`typia` is a transformer library of TypeScript, supporting below features:
|
|
329
|
+
|
|
330
|
+
- Super-fast Runtime Validators
|
|
331
|
+
- Safe JSON parse and fast stringify functions
|
|
332
|
+
- JSON schema generator
|
|
333
|
+
|
|
334
|
+
All functions in `typia` require **only one line**. You don't need any extra dedication like JSON schema definitions or decorator function calls. Just call `typia` function with only one line like `typia.assert<T>(input)`.
|
|
335
|
+
|
|
336
|
+
Also, as `typia` performs AOT (Ahead of Time) compilation skill, its performance is much faster than other competitive libaries. For an example, when comparing validate function `is()` with other competitive libraries, `typia` is maximum **15,000x times faster** than `class-validator`.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* If you adjust the regular {@link Body} decorator function to the body parameter,
|
|
7
7
|
* you can't get the full body text because the {@link Body} tries to convert the
|
|
8
|
-
* body text to JSON object. Therefore,
|
|
8
|
+
* body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
|
|
9
9
|
* decorator function to get the full body text.
|
|
10
10
|
*
|
|
11
11
|
* ```typescript
|
|
@@ -49,7 +49,7 @@ var raw_body_1 = __importDefault(require("raw-body"));
|
|
|
49
49
|
*
|
|
50
50
|
* If you adjust the regular {@link Body} decorator function to the body parameter,
|
|
51
51
|
* you can't get the full body text because the {@link Body} tries to convert the
|
|
52
|
-
* body text to JSON object. Therefore,
|
|
52
|
+
* body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
|
|
53
53
|
* decorator function to get the full body text.
|
|
54
54
|
*
|
|
55
55
|
* ```typescript
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
14
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
+
function step(op) {
|
|
17
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
20
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
+
switch (op[0]) {
|
|
22
|
+
case 0: case 1: t = op; break;
|
|
23
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
+
default:
|
|
27
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
+
if (t[2]) _.ops.pop();
|
|
32
|
+
_.trys.pop(); continue;
|
|
33
|
+
}
|
|
34
|
+
op = body.call(thisArg, _);
|
|
35
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
var CommandParser_1 = require("./internal/CommandParser");
|
|
41
|
+
var CoreSetupWizard_1 = require("./internal/CoreSetupWizard");
|
|
42
|
+
var USAGE = "Wrong command has been detected. Use like below:\n\n npx @nestia/core setup \\\n --compiler (ttypescript|ts-patch) \\\n --manager (npm|pnpm|yarn)\n\n - npx @nestia/core setup\n - npx @nestia/core setup --compiler ttypescript\n - npx @nestia/core setup --compiler ts-patch\n - npx @nestia/core setup --manager pnpm";
|
|
43
|
+
function halt(desc) {
|
|
44
|
+
console.error(desc);
|
|
45
|
+
process.exit(-1);
|
|
46
|
+
}
|
|
47
|
+
function setup() {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
+
var options, manager, compiler;
|
|
51
|
+
return __generator(this, function (_c) {
|
|
52
|
+
switch (_c.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
options = CommandParser_1.CommandParser.parse(process.argv.slice(3));
|
|
55
|
+
manager = (_a = options.manager) !== null && _a !== void 0 ? _a : "npm";
|
|
56
|
+
compiler = (_b = options.compiler) !== null && _b !== void 0 ? _b : "ttypescript";
|
|
57
|
+
if (!((compiler !== "ttypescript" && compiler !== "ts-patch") ||
|
|
58
|
+
(manager !== "npm" && manager !== "pnpm" && manager !== "yarn"))) return [3 /*break*/, 1];
|
|
59
|
+
halt(USAGE);
|
|
60
|
+
return [3 /*break*/, 5];
|
|
61
|
+
case 1:
|
|
62
|
+
if (!(compiler === "ttypescript")) return [3 /*break*/, 3];
|
|
63
|
+
return [4 /*yield*/, CoreSetupWizard_1.CoreSetupWizard.ttypescript(manager)];
|
|
64
|
+
case 2:
|
|
65
|
+
_c.sent();
|
|
66
|
+
return [3 /*break*/, 5];
|
|
67
|
+
case 3: return [4 /*yield*/, CoreSetupWizard_1.CoreSetupWizard.tsPatch(manager)];
|
|
68
|
+
case 4:
|
|
69
|
+
_c.sent();
|
|
70
|
+
_c.label = 5;
|
|
71
|
+
case 5: return [2 /*return*/];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function main() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var type;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
type = process.argv[2];
|
|
83
|
+
if (!(type === "setup")) return [3 /*break*/, 2];
|
|
84
|
+
return [4 /*yield*/, setup()];
|
|
85
|
+
case 1:
|
|
86
|
+
_a.sent();
|
|
87
|
+
return [3 /*break*/, 3];
|
|
88
|
+
case 2:
|
|
89
|
+
halt(USAGE);
|
|
90
|
+
_a.label = 3;
|
|
91
|
+
case 3: return [2 /*return*/];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
main().catch(function (exp) {
|
|
97
|
+
console.error(exp);
|
|
98
|
+
process.exit(-1);
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/executable/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0DAAyD;AACzD,8DAA6D;AAE7D,IAAM,KAAK,GAAG,sUAS4B,CAAC;AAE3C,SAAS,IAAI,CAAC,IAAY;IACtB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC;AAED,SAAe,KAAK;;;;;;;oBACV,OAAO,GAA2B,6BAAa,CAAC,KAAK,CACvD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CACxB,CAAC;oBACI,OAAO,GAAW,MAAA,OAAO,CAAC,OAAO,mCAAI,KAAK,CAAC;oBAC3C,QAAQ,GAAW,MAAA,OAAO,CAAC,QAAQ,mCAAI,aAAa,CAAC;yBAGvD,CAAA,CAAC,QAAQ,KAAK,aAAa,IAAI,QAAQ,KAAK,UAAU,CAAC;wBACvD,CAAC,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,MAAM,IAAI,OAAO,KAAK,MAAM,CAAC,CAAA,EAD/D,wBAC+D;oBAE/D,IAAI,CAAC,KAAK,CAAC,CAAC;;;yBACP,CAAA,QAAQ,KAAK,aAAa,CAAA,EAA1B,wBAA0B;oBAC/B,qBAAM,iCAAe,CAAC,WAAW,CAAC,OAAO,CAAC,EAAA;;oBAA1C,SAA0C,CAAC;;wBAC1C,qBAAM,iCAAe,CAAC,OAAO,CAAC,OAAO,CAAC,EAAA;;oBAAtC,SAAsC,CAAC;;;;;;CAC/C;AAED,SAAe,IAAI;;;;;;oBACT,IAAI,GAAuB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;yBAC7C,CAAA,IAAI,KAAK,OAAO,CAAA,EAAhB,wBAAgB;oBAAE,qBAAM,KAAK,EAAE,EAAA;;oBAAb,SAAa,CAAC;;;oBAC/B,IAAI,CAAC,KAAK,CAAC,CAAC;;;;;;CACpB;AACD,IAAI,EAAE,CAAC,KAAK,CAAC,UAAC,GAAG;IACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandParser = void 0;
|
|
4
|
+
var CommandParser;
|
|
5
|
+
(function (CommandParser) {
|
|
6
|
+
function parse(argList) {
|
|
7
|
+
var output = {};
|
|
8
|
+
argList.forEach(function (arg, i) {
|
|
9
|
+
if (arg.startsWith("--") === false)
|
|
10
|
+
return;
|
|
11
|
+
var key = arg.slice(2);
|
|
12
|
+
var value = argList[i + 1];
|
|
13
|
+
if (value === undefined || value.startsWith("--"))
|
|
14
|
+
return;
|
|
15
|
+
output[key] = value;
|
|
16
|
+
});
|
|
17
|
+
return output;
|
|
18
|
+
}
|
|
19
|
+
CommandParser.parse = parse;
|
|
20
|
+
})(CommandParser = exports.CommandParser || (exports.CommandParser = {}));
|
|
21
|
+
//# sourceMappingURL=CommandParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandParser.js","sourceRoot":"","sources":["../../../src/executable/internal/CommandParser.ts"],"names":[],"mappings":";;;AAAA,IAAiB,aAAa,CAc7B;AAdD,WAAiB,aAAa;IAC1B,SAAgB,KAAK,CAAC,OAAiB;QACnC,IAAM,MAAM,GAA2B,EAAE,CAAC;QAC1C,OAAO,CAAC,OAAO,CAAC,UAAC,GAAG,EAAE,CAAC;YACnB,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,KAAK;gBAAE,OAAO;YAE3C,IAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACzB,IAAM,KAAK,GAAuB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACjD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;gBAAE,OAAO;YAE1D,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;IAZe,mBAAK,QAYpB,CAAA;AACL,CAAC,EAdgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAc7B"}
|