nestia 2.1.1 → 2.1.2-dev.20220509
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/CONTRIBUTING.md +1 -1
- package/README.md +34 -37
- package/lib/IConfiguration.d.ts +28 -7
- package/lib/IConfiguration.d.ts.map +1 -1
- package/lib/analyses/ControllerAnalyzer.d.ts.map +1 -1
- package/lib/analyses/ControllerAnalyzer.js +30 -41
- package/lib/executable/nestia.js +0 -0
- package/lib/factories/MetadataFactory.d.ts.map +1 -1
- package/lib/factories/MetadataFactory.js +2 -6
- package/lib/factories/TypeFactry.js +1 -1
- package/package.json +1 -1
package/CONTRIBUTING.md
CHANGED
|
@@ -42,7 +42,7 @@ If you succeeded to compile, but failed to pass the test-automation, then *debug
|
|
|
42
42
|
### Adding a Test
|
|
43
43
|
As this `nestia` is not a typical library who being used by the `import` statement but a executable program generating the SDK (Software Development Kit), adding a test means that adding a demonstration project.
|
|
44
44
|
|
|
45
|
-
I know that adding a demonstration project is much difficult than adding a test function, but there's no way if newly contributed code requires a new type of testing tool. Looking at the [src/test/demonstratios](
|
|
45
|
+
I know that adding a demonstration project is much difficult than adding a test function, but there's no way if newly contributed code requires a new type of testing tool. Looking at the [src/test/demonstratios](demo) directory and traveling the demonstration projects, create a new demonstration project following their structures and styles.
|
|
46
46
|
|
|
47
47
|
Of course, if your contribution code does not require a test new project, don't mind this.
|
|
48
48
|
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npx nestia sdk "src/**/*.controller.ts" --out "src/api"
|
|
|
20
20
|
npx nestia swagger "src/controller" -- out "swagger.json"
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Don't write any `swagger` comment and DTO decorator. Just run the
|
|
23
|
+
Don't write any `swagger` comment and DTO decorator. Just run the [nestia](https://github.com/samchon/nestia) up.
|
|
24
24
|
|
|
25
25
|
- No swagger comment/decorator
|
|
26
26
|
- No DTO comment/decorator
|
|
@@ -28,7 +28,7 @@ Don't write any `swagger` comment and DTO decorator. Just run the **Nestia** up.
|
|
|
28
28
|
|
|
29
29
|
When you're developing a backend server using the `NestJS`, you don't need any extra dedication, for delivering the Rest API to the client developers, like writing the `swagger` comments or DTO decorators.
|
|
30
30
|
|
|
31
|
-
You just run this
|
|
31
|
+
You just run this [nestia](https://github.com/samchon/nestia) up, then [nestia](https://github.com/samchon/nestia) would generate the SDK automatically, by analyzing your controller classes in the compliation and runtime level. With the automatically generated SDK through this [nestia](https://github.com/samchon/nestia), client developer also does not need any extra work, like reading `swagger` and writing the duplicated interaction code. Client developer only needs to import the SDK and calls matched function with the `await` symbol.
|
|
32
32
|
|
|
33
33
|
> Even generating the `swagger.json` without any swagger comment and DTO decorator is also possible. When generating the `swagger.json`, no DTO comment and decorator is required, either. Use only the pure interface definitions.
|
|
34
34
|
|
|
@@ -67,7 +67,7 @@ export async function test_article_read(connection: api.IConnection): Promise<vo
|
|
|
67
67
|
npm install --save-dev nestia
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
Installing the
|
|
70
|
+
Installing the [nestia](https://github.com/samchon/nestia) is very easy.
|
|
71
71
|
|
|
72
72
|
Just type the `npm install --save-dev nestia` command in your NestJS backend project.
|
|
73
73
|
|
|
@@ -81,7 +81,7 @@ npx nestia sdk "src/controllers/consumers" "src/controllers/sellers" --out "src/
|
|
|
81
81
|
npx nestia sdk "src/controllers" --exclude "src/**/Fake*.ts" --out "src/api"
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
To generate a SDK library through the
|
|
84
|
+
To generate a SDK library through the [nestia](https://github.com/samchon/nestia) is very easy.
|
|
85
85
|
|
|
86
86
|
Just type the `nestia sdk <input> --out <output>` command in the console. When there're multiple source directories containing the NestJS controller classes, type all of them separating by a `space` word. If you want to exclude some directories or files from the SDK generation, the `--exclude` option would be useful.
|
|
87
87
|
|
|
@@ -97,7 +97,7 @@ npx nestia swagger "src/consumers" "src/sellers" --out "actors.json"
|
|
|
97
97
|
npx nestia swagger "src/controllers" --exclude "src/**/Fake*.ts" -out "./"
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
The
|
|
100
|
+
The [nestia](https://github.com/samchon/nestia) even supports the `swagger.json` generation and it's also extermely easy.
|
|
101
101
|
|
|
102
102
|
Jsut type the `nestia swagger <input> --out <output>` command in the console. When there're multiple source directories containing the NestJS controller classes, type all of them separating by a `space` word. If you want to exclude some directories or files from the `swagger.json` generation, the `--exclude` option would be useful.
|
|
103
103
|
|
|
@@ -108,7 +108,7 @@ Also, when generating a SDK using the cli options, `compilerOptions` would follo
|
|
|
108
108
|
npx nestia install
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
SDK library generated by the
|
|
111
|
+
SDK library generated by the [nestia](https://github.com/samchon/nestia) requires the [nestia-fetcher](https://github.com/samchon/nestia-fetcher) module. Also, the [typescript-is](https://github.com/woutervh-/typescript-is) and [typescript-json](https://github.com/samchon/typescript-json) modules can be required following your [nestia.config.ts](#nestiaconfigts) options.
|
|
112
112
|
|
|
113
113
|
The `npx nestia install` command installs those dependencies with `package.json` configuration.
|
|
114
114
|
|
|
@@ -242,9 +242,9 @@ export default config;
|
|
|
242
242
|
|
|
243
243
|
|
|
244
244
|
### Recommended Structures
|
|
245
|
-
When developing a NestJS backend server with this
|
|
245
|
+
When developing a NestJS backend server with this [nestia](https://github.com/samchon/nestia), I recommend you to follow below directory structure. The key princinple of below structure is to gathering all of the DTO interface structures into the `src/api/structures` directory and gather all of the controller classes into the `src/controllers` directory.
|
|
246
246
|
|
|
247
|
-
If you place the SDK onto the `src/api` directory and gather all of the DTO interface structures into the `src/api/structures` directory, you can publish the SDK library very easily without any special configuration. Also when you're develop the test automation program, you can implement the API testing features very convenienty through the automatically generated SDK through this
|
|
247
|
+
If you place the SDK onto the `src/api` directory and gather all of the DTO interface structures into the `src/api/structures` directory, you can publish the SDK library very easily without any special configuration. Also when you're develop the test automation program, you can implement the API testing features very convenienty through the automatically generated SDK through this [nestia](https://github.com/samchon/nestia).
|
|
248
248
|
|
|
249
249
|
- src
|
|
250
250
|
- api
|
|
@@ -258,7 +258,7 @@ If you place the SDK onto the `src/api` directory and gather all of the DTO inte
|
|
|
258
258
|
- tsconfig.json
|
|
259
259
|
- nestia.config.ts
|
|
260
260
|
|
|
261
|
-
For your deep understanding about this directory structure with this
|
|
261
|
+
For your deep understanding about this directory structure with this [nestia](https://github.com/samchon/nestia), I've prepared an example backend project. Looking around the example repository and reading the [README.md](https://github.com/samchon/backend#13-directories) of it, you can feel that such directory structure is how convenient for SDK publishing and test automation program implementation.
|
|
262
262
|
|
|
263
263
|
- https://github.com/samchon/backend
|
|
264
264
|
|
|
@@ -266,33 +266,30 @@ For your deep understanding about this directory structure with this **Nestia**,
|
|
|
266
266
|
|
|
267
267
|
|
|
268
268
|
## Demonstration
|
|
269
|
-
To demonstrate which SDK codes would be generated by this
|
|
269
|
+
To demonstrate which SDK codes would be generated by this [nestia](https://github.com/samchon/nestia):
|
|
270
270
|
|
|
271
271
|
- Representative files
|
|
272
|
-
- [DTO interface used in the RestAPI](https://github.com/samchon/nestia/tree/master/
|
|
273
|
-
- [Controllers of the NestJS](https://github.com/samchon/nestia/tree/master/
|
|
274
|
-
- [SDK generated by this
|
|
272
|
+
- [DTO interface used in the RestAPI](https://github.com/samchon/nestia/tree/master/demo/simple/src/api/structures/ISaleArticleComment.ts)
|
|
273
|
+
- [Controllers of the NestJS](https://github.com/samchon/nestia/tree/master/demo/simple/src/controllers/ConsumerSaleArticleCommentsController.ts)
|
|
274
|
+
- [SDK generated by this [nestia](https://github.com/samchon/nestia)](https://github.com/samchon/nestia/tree/master/demo/simple/src/api/functional/consumers/sales/articles/comments/index.ts)
|
|
275
|
+
- [`swagger.json` generated by this [nestia](https://github.com/samchon/nestia)](https://github.com/samchon/nestia/tree/master/demo/simple/swagger.json)
|
|
275
276
|
- Demonstration Projects
|
|
276
|
-
- [
|
|
277
|
-
- [
|
|
278
|
-
- [
|
|
279
|
-
- [
|
|
280
|
-
- [
|
|
281
|
-
- [exclude](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/exclude): Exclude option using the `--exclude` commad
|
|
282
|
-
- [nestia.config.ts](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/nestia.config.ts): Configured `nestia.config.ts` with `assert` mode
|
|
283
|
-
- [reference](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/reference): Configured input files as `src/**/*.controller.ts`
|
|
284
|
-
- [tsconfig.json](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/tsconfig.json): Special configuration through the `tsconfig.json`
|
|
277
|
+
- [encrypt](https://github.com/samchon/nestia/tree/master/demo/encrypt): Request and response body are fully encrypted
|
|
278
|
+
- [generic](https://github.com/samchon/nestia/tree/master/demo/generic): Generic typed controller classes
|
|
279
|
+
- [recursive](https://github.com/samchon/nestia/tree/master/demo/recursive): Recursive DTO interface, [swagger editor](https://editor.swagger.io) can't expresss it
|
|
280
|
+
- [simple](https://github.com/samchon/nestia/tree/master/demo/simple): Simple DTO interface and controller class
|
|
281
|
+
- [union](https://github.com/samchon/nestia/tree/master/demo/union): Only [nestia](https://github.com/samchon/nestia) can handle the union typed DTO interface
|
|
285
282
|
|
|
286
283
|
### DTO
|
|
287
|
-
|
|
284
|
+
Using pure interface type as DTO is possible.
|
|
288
285
|
|
|
289
|
-
You dont' need to define any extra comment or decorator function to make the DTO (Data Transfer Object). Just define the DTO as a pure interface structure, then
|
|
286
|
+
You dont' need to define any extra comment or decorator function to make the DTO (Data Transfer Object). Just define the DTO as a pure interface structure, then [nestia](https://github.com/samchon/nestia) will do everything instead of you.
|
|
290
287
|
|
|
291
288
|
If you're afraiding because your type is union or intersection, I can say that it does not matter. Even when generic or conditional type comes, it does not matter. Just enjoy the pure TypeScript type.
|
|
292
289
|
|
|
293
290
|
```typescript
|
|
294
291
|
/**
|
|
295
|
-
* Comment wrote on
|
|
292
|
+
* Comment wrote on a sale related article.
|
|
296
293
|
*
|
|
297
294
|
* @author Jeongho Nam - https://github.com/samchon
|
|
298
295
|
*/
|
|
@@ -355,7 +352,7 @@ export namespace ISaleComment
|
|
|
355
352
|
```
|
|
356
353
|
|
|
357
354
|
### Controller
|
|
358
|
-
If you've decided to adapt this
|
|
355
|
+
If you've decided to adapt this [nestia](https://github.com/samchon/nestia) and you want to generate the SDK directly, you don't need any extra work. Just keep you controller class down and do noting. The only one exceptional case that you need an extra dedication is, when you want to explain about the API function to the client developers through the comments.
|
|
359
356
|
|
|
360
357
|
```typescript
|
|
361
358
|
@nest.Controller("consumers/:section/sales/:saleId/questions")
|
|
@@ -385,7 +382,7 @@ export class ConsumerSaleQuestionsController
|
|
|
385
382
|
```
|
|
386
383
|
|
|
387
384
|
### SDK
|
|
388
|
-
When you run the
|
|
385
|
+
When you run the [nestia](https://github.com/samchon/nestia) up using the upper controller class `ConsumerSaleQuestionsController`, the [nestia](https://github.com/samchon/nestia) would generate below function for the client developers, by analyzing the `ConsumerSaleQuestionsController` class in the compilation and runtime level.
|
|
389
386
|
|
|
390
387
|
As you can see, the comments from the `ConsumerSaleQuestionsController.store()` are fully copied to the SDK function. Therefore, if you want to deliver detailed description about the API function, writing the detailed comment would be tne best choice.
|
|
391
388
|
|
|
@@ -445,7 +442,7 @@ export namespace store
|
|
|
445
442
|
### `swagger.json`
|
|
446
443
|
Even the `swagger.json` generation does not require any swagger comment and DTO decorator.
|
|
447
444
|
|
|
448
|
-
The
|
|
445
|
+
The [nestia](https://github.com/samchon/nestia) will generate the perfect `swagger.json` automatically, by analyzing your source code (DTO interface and controller class) in the compilation and runtime level. Furthermore, your descriptive comments would be automatically assigned into the adequate `description` property in the `swagger.json`.
|
|
449
446
|
|
|
450
447
|
```json
|
|
451
448
|
{
|
|
@@ -617,20 +614,20 @@ The **Nestia** will generate the perfect `swagger.json` automatically, by analyz
|
|
|
617
614
|
### Template Project
|
|
618
615
|
https://github.com/samchon/backend
|
|
619
616
|
|
|
620
|
-
I support template backend project using this
|
|
617
|
+
I support template backend project using this [nestia](https://github.com/samchon/nestia)* library, [backend](https://github.com/samchon/backend).
|
|
621
618
|
|
|
622
|
-
Reading the README content of the [backend](https://github.com/samchon/backend) template repository, you can find lots of example backend projects who've been generated from the [backend](https://github.com/samchon/backend). Furthermore, those example projects guide how to generate SDK library from the
|
|
619
|
+
Reading the README content of the [backend](https://github.com/samchon/backend) template repository, you can find lots of example backend projects who've been generated from the [backend](https://github.com/samchon/backend). Furthermore, those example projects guide how to generate SDK library from the [nestia](https://github.com/samchon/nestia) and how to distribute the SDK library thorugh the NPM module.
|
|
623
620
|
|
|
624
|
-
Therefore, if you're planning to compose your own backend project using this
|
|
621
|
+
Therefore, if you're planning to compose your own backend project using this [nestia](https://github.com/samchon/nestia), I recommend you to create the repository and learn from the [backend](https://github.com/samchon/backend) template project.
|
|
625
622
|
|
|
626
623
|
### Nestia-Helper
|
|
627
624
|
https://github.com/samchon/nestia-helper
|
|
628
625
|
|
|
629
|
-
Helper library of the `NestJS` with
|
|
626
|
+
Helper library of the `NestJS` with [nestia](https://github.com/samchon/nestia).
|
|
630
627
|
|
|
631
|
-
[nestia-helper](https://github.com/samchon/nestia-helper) is a type of helper library for `Nestia` by enhancing decorator functions. Also, all of the decorator functions provided by this [nestia-helper](https://github.com/samchon/nestia-helper) are all fully compatible with the
|
|
628
|
+
[nestia-helper](https://github.com/samchon/nestia-helper) is a type of helper library for `Nestia` by enhancing decorator functions. Also, all of the decorator functions provided by this [nestia-helper](https://github.com/samchon/nestia-helper) are all fully compatible with the [nestia](https://github.com/samchon/nestia), who can generate SDK library by analyzing NestJS controller classes in the compilation level.
|
|
632
629
|
|
|
633
|
-
Of course, this [nestia-helper](https://github.com/samchon/nestia-helper) is not essential for utilizing the `NestJS` and
|
|
630
|
+
Of course, this [nestia-helper](https://github.com/samchon/nestia-helper) is not essential for utilizing the `NestJS` and [nestia](https://github.com/samchon/nestia). You can generate SDK library of your NestJS developed backend server without this [nestia-helper](https://github.com/samchon/nestia-helper). However, as decorator functions of this [nestia-helper](https://github.com/samchon/nestia-helper) is enough strong, I recommend you to adapt this [nestia-helper](https://github.com/samchon/nestia-helper) when using `NestJS` and [nestia](https://github.com/samchon/nestia).
|
|
634
631
|
|
|
635
632
|
- Supported decorator functions
|
|
636
633
|
- [EncryptedController](https://github.com/samchon/nestia-helper#encryptedcontroller), [EncryptedModule](https://github.com/samchon/nestia-helper#encryptedmodule)
|
|
@@ -643,7 +640,7 @@ https://github.com/samchon/safe-typeorm
|
|
|
643
640
|
|
|
644
641
|
[safe-typeorm](https://github.com/samchon/safe-typeorm) is another library that what I've developed, helping `TypeORM` in the compilation level and optimizes DB performance automatically without any extra dedication.
|
|
645
642
|
|
|
646
|
-
Therefore, this
|
|
643
|
+
Therefore, this [nestia](https://github.com/samchon/nestia) makes you to be much convenient in the API interaction level and safe-typeorm helps you to be much convenient in the DB interaction level. With those [nestia](https://github.com/samchon/nestia) and [safe-typeorm](https://github.com/samchon/safe-typeorm), let's implement the backend server much easily and conveniently.
|
|
647
644
|
|
|
648
645
|
- When writing [**SQL query**](https://github.com/samchon/safe-typeorm#safe-query-builder),
|
|
649
646
|
- Errors would be detected in the **compilation** level
|
|
@@ -658,11 +655,11 @@ Therefore, this **Nestia** makes you to be much convenient in the API interactio
|
|
|
658
655
|
- Sequence of tables would be automatically sorted by analyzing dependencies
|
|
659
656
|
- The **performance** would be **automatically tuned**
|
|
660
657
|
|
|
661
|
-

|
|
662
659
|
|
|
663
660
|
### Archidraw
|
|
664
661
|
https://www.archisketch.com/
|
|
665
662
|
|
|
666
663
|
I have special thanks to the Archidraw, where I'm working for.
|
|
667
664
|
|
|
668
|
-
The Archidraw is a great IT company developing 3D interior editor and lots of solutions based on the 3D assets. Also, the Archidraw is the first company who had adopted this
|
|
665
|
+
The Archidraw is a great IT company developing 3D interior editor and lots of solutions based on the 3D assets. Also, the Archidraw is the first company who had adopted this [nestia](https://github.com/samchon/nestia) on their commercial backend project, even this [nestia](https://github.com/samchon/nestia) was in the alpha level.
|
package/lib/IConfiguration.d.ts
CHANGED
|
@@ -11,31 +11,52 @@ export interface IConfiguration {
|
|
|
11
11
|
input: string | string[] | IConfiguration.IInput;
|
|
12
12
|
/**
|
|
13
13
|
* Output directory that SDK would be placed in.
|
|
14
|
+
*
|
|
15
|
+
* If not configured, you can't build the SDK library.
|
|
14
16
|
*/
|
|
15
17
|
output?: string;
|
|
16
18
|
/**
|
|
17
19
|
* Compiler options for the TypeScript.
|
|
18
20
|
*
|
|
19
|
-
* If omitted
|
|
21
|
+
* If you've omitted this property or the assigned property cannot fully cover the
|
|
22
|
+
* `tsconfig.json`, the properties from the `tsconfig.json` would be assigned to here.
|
|
23
|
+
* Otherwise, this property has been configured and it's detailed values are different
|
|
24
|
+
* with the `tsconfig.json`, this property values would be used instead.
|
|
25
|
+
*
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import ts from "typescript";
|
|
28
|
+
*
|
|
29
|
+
* const tsconfig: ts.TsConfig;
|
|
30
|
+
* const nestiaConfig: IConfiguration;
|
|
31
|
+
*
|
|
32
|
+
* const compilerOptions: ts.CompilerOptions = {
|
|
33
|
+
* ...tsconfig.compilerOptions,
|
|
34
|
+
* ...(nestiaConfig.compilerOptions || {})
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
20
37
|
*/
|
|
21
38
|
compilerOptions?: ts.CompilerOptions;
|
|
22
39
|
/**
|
|
23
40
|
* Whether to assert parameter types or not.
|
|
24
41
|
*
|
|
25
|
-
* If you configure this
|
|
26
|
-
* checked through the [typescript-is](https://github.com/woutervh-/typescript-is).
|
|
42
|
+
* If you configure this property to be `true`, all of the function parameters would be
|
|
43
|
+
* checked through the [typescript-is](https://github.com/woutervh-/typescript-is). This
|
|
44
|
+
* option would make your SDK library slower, but would enahcne the type safety even in
|
|
45
|
+
* the runtime level.
|
|
27
46
|
*/
|
|
28
47
|
assert?: boolean;
|
|
29
48
|
/**
|
|
30
49
|
* Whether to optimize JSON string conversion 2x faster or not.
|
|
31
50
|
*
|
|
32
|
-
* If you configure this
|
|
51
|
+
* If you configure this property to be `true`, the SDK library would utilize the
|
|
33
52
|
* [typescript-json](https://github.com/samchon/typescript-json) and the JSON string
|
|
34
53
|
* conversion speed really be 2x faster.
|
|
35
54
|
*/
|
|
36
55
|
json?: boolean;
|
|
37
56
|
/**
|
|
38
57
|
* Building `swagger.json` is also possible.
|
|
58
|
+
*
|
|
59
|
+
* If not specified, you can't build the `swagger.json`.
|
|
39
60
|
*/
|
|
40
61
|
swagger?: IConfiguration.ISwagger;
|
|
41
62
|
}
|
|
@@ -61,9 +82,9 @@ export declare namespace IConfiguration {
|
|
|
61
82
|
/**
|
|
62
83
|
* Output path of the `swagger.json`.
|
|
63
84
|
*
|
|
64
|
-
* If you've
|
|
65
|
-
* Otherwise you
|
|
66
|
-
* be renamed to
|
|
85
|
+
* If you've configured only directory, the file name would be the `swagger.json`.
|
|
86
|
+
* Otherwise you've configured the full path with file name and extension, the
|
|
87
|
+
* `swagger.json` file would be renamed to it.
|
|
67
88
|
*/
|
|
68
89
|
output: string;
|
|
69
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IConfiguration.d.ts","sourceRoot":"","sources":["../src/IConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAE3B;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC;IAEjD
|
|
1
|
+
{"version":3,"file":"IConfiguration.d.ts","sourceRoot":"","sources":["../src/IConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAE3B;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC;IAEjD;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC;IAErC;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;;OAIG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC;CACrC;AACD,yBAAiB,cAAc,CAC/B;IACI;;;OAGG;IACH,UAAiB,MAAM;QAEnB;;WAEG;QACH,OAAO,EAAE,MAAM,EAAE,CAAC;QAElB;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACtB;IAED;;OAEG;IACH,UAAiB,QAAQ;QAErB;;;;;;WAMG;QACH,MAAM,EAAE,MAAM,CAAC;KAClB;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ControllerAnalyzer.d.ts","sourceRoot":"","sources":["../../src/analyses/ControllerAnalyzer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAM9C,yBAAiB,kBAAkB,CACnC;IACI,SAAgB,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,GAAG,MAAM,EAAE,CAc7G;
|
|
1
|
+
{"version":3,"file":"ControllerAnalyzer.d.ts","sourceRoot":"","sources":["../../src/analyses/ControllerAnalyzer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAM9C,yBAAiB,kBAAkB,CACnC;IACI,SAAgB,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,GAAG,MAAM,EAAE,CAc7G;CAqJJ"}
|
|
@@ -76,47 +76,36 @@ var ControllerAnalyzer;
|
|
|
76
76
|
CLASS
|
|
77
77
|
--------------------------------------------------------- */
|
|
78
78
|
function _Analyze_controller(checker, controller, classNode) {
|
|
79
|
-
var e_1, _a
|
|
80
|
-
var ret = [];
|
|
79
|
+
var e_1, _a;
|
|
81
80
|
var classType = checker.getTypeAtLocation(classNode);
|
|
82
81
|
var genericDict = GenericAnalyzer_1.GenericAnalyzer.analyze(checker, classNode);
|
|
82
|
+
var ret = [];
|
|
83
|
+
var _loop_1 = function (property) {
|
|
84
|
+
// GET METHOD DECLARATION
|
|
85
|
+
var declaration = (property.declarations || [])[0];
|
|
86
|
+
if (!declaration || !typescript_1.default.isMethodDeclaration(declaration))
|
|
87
|
+
return "continue";
|
|
88
|
+
// IDENTIFIER MUST BE
|
|
89
|
+
var identifier = declaration.name;
|
|
90
|
+
if (!typescript_1.default.isIdentifier(identifier))
|
|
91
|
+
return "continue";
|
|
92
|
+
// ANALYZED WITH THE REFLECTED-FUNCTION
|
|
93
|
+
var runtime = controller.functions.find(function (f) { return f.name === identifier.escapedText; });
|
|
94
|
+
if (runtime === undefined)
|
|
95
|
+
return "continue";
|
|
96
|
+
var route = _Analyze_function(checker, controller, genericDict, runtime, property);
|
|
97
|
+
ret.push(route);
|
|
98
|
+
};
|
|
83
99
|
try {
|
|
84
|
-
for (var
|
|
85
|
-
var property =
|
|
86
|
-
|
|
87
|
-
var _loop_1 = function (declaration) {
|
|
88
|
-
// TARGET ONLY METHOD
|
|
89
|
-
if (!typescript_1.default.isMethodDeclaration(declaration))
|
|
90
|
-
return "continue";
|
|
91
|
-
// IT MUST BE
|
|
92
|
-
var identifier = declaration.name;
|
|
93
|
-
if (!typescript_1.default.isIdentifier(identifier))
|
|
94
|
-
return "continue";
|
|
95
|
-
// ANALYZED WITH THE REFLECTED-FUNCTION
|
|
96
|
-
var func = controller.functions.find(function (f) { return f.name === identifier.escapedText; });
|
|
97
|
-
if (func !== undefined)
|
|
98
|
-
ret.push(_Analyze_function(checker, controller, genericDict, func, declaration));
|
|
99
|
-
};
|
|
100
|
-
try {
|
|
101
|
-
for (var _e = (e_2 = void 0, __values(property.declarations)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
102
|
-
var declaration = _f.value;
|
|
103
|
-
_loop_1(declaration);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
107
|
-
finally {
|
|
108
|
-
try {
|
|
109
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
110
|
-
}
|
|
111
|
-
finally { if (e_2) throw e_2.error; }
|
|
112
|
-
}
|
|
113
|
-
}
|
|
100
|
+
for (var _b = __values(classType.getProperties()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
101
|
+
var property = _c.value;
|
|
102
|
+
_loop_1(property);
|
|
114
103
|
}
|
|
115
104
|
}
|
|
116
105
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
117
106
|
finally {
|
|
118
107
|
try {
|
|
119
|
-
if (
|
|
108
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
120
109
|
}
|
|
121
110
|
finally { if (e_1) throw e_1.error; }
|
|
122
111
|
}
|
|
@@ -125,15 +114,16 @@ var ControllerAnalyzer;
|
|
|
125
114
|
/* ---------------------------------------------------------
|
|
126
115
|
FUNCTION
|
|
127
116
|
--------------------------------------------------------- */
|
|
128
|
-
function _Analyze_function(checker, controller, genericDict, func,
|
|
117
|
+
function _Analyze_function(checker, controller, genericDict, func, symbol) {
|
|
129
118
|
// PREPARE ASSETS
|
|
130
|
-
var
|
|
119
|
+
var type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
|
|
120
|
+
var signature = checker.getSignaturesOfType(type, typescript_1.default.SignatureKind.Call)[0];
|
|
131
121
|
if (signature === undefined)
|
|
132
|
-
throw new Error("Error on ControllerAnalyzer._Analyze_function(): unable to get the
|
|
122
|
+
throw new Error("Error on ControllerAnalyzer._Analyze_function(): unable to get the signature from the ".concat(controller.name, ".").concat(func.name, "()."));
|
|
133
123
|
var importDict = new HashMap_1.HashMap();
|
|
134
124
|
// EXPLORE CHILDREN TYPES
|
|
135
|
-
var parameters = func.parameters.map(function (param) { return _Analyze_parameter(checker, genericDict, importDict, controller, func.name, param,
|
|
136
|
-
var output = ImportAnalyzer_1.ImportAnalyzer.analyze(checker, genericDict, importDict,
|
|
125
|
+
var parameters = func.parameters.map(function (param) { return _Analyze_parameter(checker, genericDict, importDict, controller, func.name, param, signature.getParameters()[param.index]); });
|
|
126
|
+
var output = ImportAnalyzer_1.ImportAnalyzer.analyze(checker, genericDict, importDict, signature.getReturnType());
|
|
137
127
|
var imports = importDict
|
|
138
128
|
.toJSON()
|
|
139
129
|
.map(function (pair) { return [pair.first, pair.second.toJSON()]; });
|
|
@@ -154,9 +144,8 @@ var ControllerAnalyzer;
|
|
|
154
144
|
/* ---------------------------------------------------------
|
|
155
145
|
PARAMETER
|
|
156
146
|
--------------------------------------------------------- */
|
|
157
|
-
function _Analyze_parameter(checker, genericDict, importDict, controller, funcName, param,
|
|
158
|
-
var
|
|
159
|
-
var type = checker.getTypeOfSymbolAtLocation(symbol, declaration);
|
|
147
|
+
function _Analyze_parameter(checker, genericDict, importDict, controller, funcName, param, symbol) {
|
|
148
|
+
var type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
|
|
160
149
|
var name = symbol.getEscapedName().toString();
|
|
161
150
|
// VALIDATE PARAMETERS
|
|
162
151
|
if ((param.category === "query" || param.category === "body") && param.field !== undefined)
|
package/lib/executable/nestia.js
CHANGED
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetadataFactory.d.ts","sourceRoot":"","sources":["../../src/factories/MetadataFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"MetadataFactory.d.ts","sourceRoot":"","sources":["../../src/factories/MetadataFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,yBAAiB,eAAe,CAChC;IACI,MAAM,QAAQ,UAAU,GAAG,kBAAkB,CAAC;IAE9C,SAAgB,QAAQ,CAEhB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,EACpB,UAAU,GAAE,UAAiC,GAC9C,SAAS,CAAC,YAAY,GAAG,IAAI,CAenC;CA0NJ"}
|
|
@@ -43,7 +43,6 @@ exports.MetadataFactory = void 0;
|
|
|
43
43
|
var crypto_1 = __importDefault(require("crypto"));
|
|
44
44
|
var typescript_1 = __importDefault(require("typescript"));
|
|
45
45
|
var Singleton_1 = require("tstl/thread/Singleton");
|
|
46
|
-
var CommentFactory_1 = require("./CommentFactory");
|
|
47
46
|
var MetadataCollection_1 = require("./MetadataCollection");
|
|
48
47
|
var TypeFactry_1 = require("./TypeFactry");
|
|
49
48
|
var MetadataFactory;
|
|
@@ -208,11 +207,8 @@ var MetadataFactory;
|
|
|
208
207
|
var type = checker.getTypeOfSymbolAtLocation(prop, node);
|
|
209
208
|
// CHILD METADATA BY ADDITIONAL EXPLORATION
|
|
210
209
|
var child = explore(collection, checker, type);
|
|
211
|
-
if (child)
|
|
212
|
-
|
|
213
|
-
child.required = false;
|
|
214
|
-
child.description = CommentFactory_1.CommentFactory.generate(prop.getDocumentationComment(checker));
|
|
215
|
-
}
|
|
210
|
+
if (child && node.questionToken)
|
|
211
|
+
child.required = false;
|
|
216
212
|
object.properties[key] = child;
|
|
217
213
|
}
|
|
218
214
|
}
|
|
@@ -43,7 +43,7 @@ var TypeFactory;
|
|
|
43
43
|
}
|
|
44
44
|
function full_name(checker, type) {
|
|
45
45
|
// PRIMITIVE
|
|
46
|
-
var symbol = type.
|
|
46
|
+
var symbol = type.aliasSymbol || type.getSymbol();
|
|
47
47
|
if (symbol === undefined)
|
|
48
48
|
return checker.typeToString(type, undefined, undefined);
|
|
49
49
|
// UNION OR INTERSECT
|