@nestia/core 2.6.2 → 2.6.3

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 (32) hide show
  1. package/package.json +4 -4
  2. package/src/decorators/EncryptedBody.ts +105 -105
  3. package/src/decorators/EncryptedModule.ts +96 -96
  4. package/src/decorators/PlainBody.ts +75 -75
  5. package/src/decorators/SwaggerCustomizer.ts +116 -116
  6. package/src/decorators/TypedBody.ts +62 -62
  7. package/src/decorators/TypedException.ts +90 -90
  8. package/src/decorators/TypedFormData.ts +219 -219
  9. package/src/decorators/TypedQuery.ts +251 -251
  10. package/src/decorators/TypedRoute.ts +144 -144
  11. package/src/decorators/internal/get_path_and_querify.ts +106 -106
  12. package/src/decorators/internal/load_controller.ts +51 -51
  13. package/src/decorators/internal/validate_request_body.ts +72 -72
  14. package/src/decorators/internal/validate_request_form_data.ts +75 -75
  15. package/src/decorators/internal/validate_request_headers.ts +83 -83
  16. package/src/decorators/internal/validate_request_query.ts +71 -71
  17. package/src/module.ts +16 -16
  18. package/src/options/IRequestFormDataProps.ts +27 -27
  19. package/src/programmers/PlainBodyProgrammer.ts +52 -52
  20. package/src/programmers/TypedExceptionProgrammer.ts +71 -71
  21. package/src/programmers/TypedFormDataBodyProgrammer.ts +108 -108
  22. package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
  23. package/src/structures/ISwagger.ts +91 -91
  24. package/src/structures/ISwaggerComponents.ts +29 -29
  25. package/src/structures/ISwaggerInfo.ts +80 -80
  26. package/src/structures/ISwaggerRoute.ts +50 -50
  27. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  28. package/src/transformers/NodeTransformer.ts +16 -16
  29. package/src/transformers/ParameterDecoratorTransformer.ts +120 -120
  30. package/src/transformers/TypedExceptionTransformer.ts +48 -48
  31. package/src/transformers/TypedRouteTransformer.ts +88 -88
  32. package/src/utils/Singleton.ts +20 -20
@@ -1,96 +1,96 @@
1
- import ts from "typescript";
2
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
- import { StatementFactory } from "typia/lib/factories/StatementFactory";
6
- import { FunctionImporter } from "typia/lib/programmers/helpers/FunctionImporeter";
7
- import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
8
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
9
- import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
10
- import { IProject } from "typia/lib/transformers/IProject";
11
- import { TransformerError } from "typia/lib/transformers/TransformerError";
12
-
13
- export namespace HttpQuerifyProgrammer {
14
- export const write =
15
- (project: IProject) =>
16
- (modulo: ts.LeftHandSideExpression) =>
17
- (type: ts.Type): ts.ArrowFunction => {
18
- // GET OBJECT TYPE
19
- const importer: FunctionImporter = new FunctionImporter(modulo.getText());
20
- const collection: MetadataCollection = new MetadataCollection();
21
- const result = MetadataFactory.analyze(project.checker)({
22
- escape: false,
23
- constant: true,
24
- absorb: true,
25
- validate: HttpQueryProgrammer.validate,
26
- })(collection)(type);
27
- if (result.success === false)
28
- throw TransformerError.from(
29
- `nestia.core.TypedQuery.${importer.method}`,
30
- )(result.errors);
31
-
32
- const object: MetadataObject = result.data.objects[0]!;
33
- return ts.factory.createArrowFunction(
34
- undefined,
35
- undefined,
36
- [IdentifierFactory.parameter("input")],
37
- undefined,
38
- undefined,
39
- ts.factory.createBlock(
40
- [
41
- ...importer.declare(modulo),
42
- StatementFactory.constant(
43
- "output",
44
- ts.factory.createNewExpression(
45
- ts.factory.createIdentifier("URLSearchParams"),
46
- undefined,
47
- [],
48
- ),
49
- ),
50
- ...object.properties.map((p) =>
51
- ts.factory.createExpressionStatement(
52
- decode(p.key.constants[0]!.values[0] as string)(p.value),
53
- ),
54
- ),
55
- ts.factory.createReturnStatement(
56
- ts.factory.createIdentifier("output"),
57
- ),
58
- ],
59
- true,
60
- ),
61
- );
62
- };
63
-
64
- const decode =
65
- (key: string) =>
66
- (value: Metadata): ts.CallExpression =>
67
- !!value.arrays.length
68
- ? ts.factory.createCallExpression(
69
- IdentifierFactory.access(
70
- IdentifierFactory.access(ts.factory.createIdentifier("input"))(
71
- key,
72
- ),
73
- )("forEach"),
74
- undefined,
75
- [
76
- ts.factory.createArrowFunction(
77
- undefined,
78
- undefined,
79
- [IdentifierFactory.parameter("elem")],
80
- undefined,
81
- undefined,
82
- append(key)(ts.factory.createIdentifier("elem")),
83
- ),
84
- ],
85
- )
86
- : append(key)(
87
- IdentifierFactory.access(ts.factory.createIdentifier("input"))(key),
88
- );
89
-
90
- const append = (key: string) => (elem: ts.Expression) =>
91
- ts.factory.createCallExpression(
92
- IdentifierFactory.access(ts.factory.createIdentifier("output"))("append"),
93
- undefined,
94
- [ts.factory.createStringLiteral(key), elem],
95
- );
96
- }
1
+ import ts from "typescript";
2
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
+ import { StatementFactory } from "typia/lib/factories/StatementFactory";
6
+ import { FunctionImporter } from "typia/lib/programmers/helpers/FunctionImporeter";
7
+ import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
8
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
9
+ import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
10
+ import { IProject } from "typia/lib/transformers/IProject";
11
+ import { TransformerError } from "typia/lib/transformers/TransformerError";
12
+
13
+ export namespace HttpQuerifyProgrammer {
14
+ export const write =
15
+ (project: IProject) =>
16
+ (modulo: ts.LeftHandSideExpression) =>
17
+ (type: ts.Type): ts.ArrowFunction => {
18
+ // GET OBJECT TYPE
19
+ const importer: FunctionImporter = new FunctionImporter(modulo.getText());
20
+ const collection: MetadataCollection = new MetadataCollection();
21
+ const result = MetadataFactory.analyze(project.checker)({
22
+ escape: false,
23
+ constant: true,
24
+ absorb: true,
25
+ validate: HttpQueryProgrammer.validate,
26
+ })(collection)(type);
27
+ if (result.success === false)
28
+ throw TransformerError.from(
29
+ `nestia.core.TypedQuery.${importer.method}`,
30
+ )(result.errors);
31
+
32
+ const object: MetadataObject = result.data.objects[0]!;
33
+ return ts.factory.createArrowFunction(
34
+ undefined,
35
+ undefined,
36
+ [IdentifierFactory.parameter("input")],
37
+ undefined,
38
+ undefined,
39
+ ts.factory.createBlock(
40
+ [
41
+ ...importer.declare(modulo),
42
+ StatementFactory.constant(
43
+ "output",
44
+ ts.factory.createNewExpression(
45
+ ts.factory.createIdentifier("URLSearchParams"),
46
+ undefined,
47
+ [],
48
+ ),
49
+ ),
50
+ ...object.properties.map((p) =>
51
+ ts.factory.createExpressionStatement(
52
+ decode(p.key.constants[0]!.values[0] as string)(p.value),
53
+ ),
54
+ ),
55
+ ts.factory.createReturnStatement(
56
+ ts.factory.createIdentifier("output"),
57
+ ),
58
+ ],
59
+ true,
60
+ ),
61
+ );
62
+ };
63
+
64
+ const decode =
65
+ (key: string) =>
66
+ (value: Metadata): ts.CallExpression =>
67
+ !!value.arrays.length
68
+ ? ts.factory.createCallExpression(
69
+ IdentifierFactory.access(
70
+ IdentifierFactory.access(ts.factory.createIdentifier("input"))(
71
+ key,
72
+ ),
73
+ )("forEach"),
74
+ undefined,
75
+ [
76
+ ts.factory.createArrowFunction(
77
+ undefined,
78
+ undefined,
79
+ [IdentifierFactory.parameter("elem")],
80
+ undefined,
81
+ undefined,
82
+ append(key)(ts.factory.createIdentifier("elem")),
83
+ ),
84
+ ],
85
+ )
86
+ : append(key)(
87
+ IdentifierFactory.access(ts.factory.createIdentifier("input"))(key),
88
+ );
89
+
90
+ const append = (key: string) => (elem: ts.Expression) =>
91
+ ts.factory.createCallExpression(
92
+ IdentifierFactory.access(ts.factory.createIdentifier("output"))("append"),
93
+ undefined,
94
+ [ts.factory.createStringLiteral(key), elem],
95
+ );
96
+ }
@@ -1,91 +1,91 @@
1
- import { ISwaggerComponents } from "./ISwaggerComponents";
2
- import { ISwaggerInfo } from "./ISwaggerInfo";
3
- import { ISwaggerRoute } from "./ISwaggerRoute";
4
-
5
- /**
6
- * Swagger Document.
7
- *
8
- * `ISwagger` is a data structure representing content of `swagger.json` file
9
- * generated by Nestia. Note that, this is not an universal structure, but a dedicated
10
- * structure only for Nestia.
11
- *
12
- * @author Jeongho Nam - https://github.com/samchon
13
- */
14
- export interface ISwagger {
15
- /**
16
- * The version of the OpenAPI document.
17
- *
18
- * Nestia always generate OpenAPI 3.0.x document.
19
- */
20
- openapi: `3.0.${number}`;
21
-
22
- /**
23
- * List of servers that provide the API.
24
- */
25
- servers: ISwagger.IServer[];
26
-
27
- /**
28
- * Information about the API.
29
- */
30
- info: ISwaggerInfo;
31
-
32
- /**
33
- * The available paths and operations for the API.
34
- *
35
- * The 1st key is the path, and the 2nd key is the HTTP method.
36
- */
37
- paths: Record<string, Record<string, ISwaggerRoute>>;
38
-
39
- /**
40
- * An object to hold reusable data structures.
41
- *
42
- * It stores both DTO schemas and security schemes.
43
- *
44
- * For reference, `nestia` defines every object and alias types as reusable DTO
45
- * schemas. The alias type means that defined by `type` keyword in TypeScript.
46
- */
47
- components: ISwaggerComponents;
48
-
49
- // /**
50
- // * A declaration of which security mechanisms can be used across the API.
51
- // *
52
- // * When this property be configured, it would be overwritten in every API routes.
53
- // *
54
- // * For reference, key means the name of security scheme and value means the `scopes`.
55
- // * The `scopes` can be used only when target security scheme is `oauth2` type,
56
- // * especially for {@link ISwaggerSecurityScheme.IOAuth2.IFlow.scopes} property.
57
- // */
58
- // security?: Record<string, string[]>[];
59
- }
60
- export namespace ISwagger {
61
- /**
62
- * Remote server definition.
63
- */
64
- export interface IServer {
65
- /**
66
- * A URL to the target host.
67
- *
68
- * @format uri
69
- */
70
- url: string;
71
-
72
- /**
73
- * An optional string describing the target server.
74
- */
75
- description?: string;
76
- }
77
-
78
- export interface IExternalDocs {
79
- /**
80
- * The URL for target documentation.
81
- *
82
- * @format uri
83
- */
84
- url: string;
85
-
86
- /**
87
- * A short description of the target documentation.
88
- */
89
- description?: string;
90
- }
91
- }
1
+ import { ISwaggerComponents } from "./ISwaggerComponents";
2
+ import { ISwaggerInfo } from "./ISwaggerInfo";
3
+ import { ISwaggerRoute } from "./ISwaggerRoute";
4
+
5
+ /**
6
+ * Swagger Document.
7
+ *
8
+ * `ISwagger` is a data structure representing content of `swagger.json` file
9
+ * generated by Nestia. Note that, this is not an universal structure, but a dedicated
10
+ * structure only for Nestia.
11
+ *
12
+ * @author Jeongho Nam - https://github.com/samchon
13
+ */
14
+ export interface ISwagger {
15
+ /**
16
+ * The version of the OpenAPI document.
17
+ *
18
+ * Nestia always generate OpenAPI 3.0.x document.
19
+ */
20
+ openapi: `3.0.${number}`;
21
+
22
+ /**
23
+ * List of servers that provide the API.
24
+ */
25
+ servers: ISwagger.IServer[];
26
+
27
+ /**
28
+ * Information about the API.
29
+ */
30
+ info: ISwaggerInfo;
31
+
32
+ /**
33
+ * The available paths and operations for the API.
34
+ *
35
+ * The 1st key is the path, and the 2nd key is the HTTP method.
36
+ */
37
+ paths: Record<string, Record<string, ISwaggerRoute>>;
38
+
39
+ /**
40
+ * An object to hold reusable data structures.
41
+ *
42
+ * It stores both DTO schemas and security schemes.
43
+ *
44
+ * For reference, `nestia` defines every object and alias types as reusable DTO
45
+ * schemas. The alias type means that defined by `type` keyword in TypeScript.
46
+ */
47
+ components: ISwaggerComponents;
48
+
49
+ // /**
50
+ // * A declaration of which security mechanisms can be used across the API.
51
+ // *
52
+ // * When this property be configured, it would be overwritten in every API routes.
53
+ // *
54
+ // * For reference, key means the name of security scheme and value means the `scopes`.
55
+ // * The `scopes` can be used only when target security scheme is `oauth2` type,
56
+ // * especially for {@link ISwaggerSecurityScheme.IOAuth2.IFlow.scopes} property.
57
+ // */
58
+ // security?: Record<string, string[]>[];
59
+ }
60
+ export namespace ISwagger {
61
+ /**
62
+ * Remote server definition.
63
+ */
64
+ export interface IServer {
65
+ /**
66
+ * A URL to the target host.
67
+ *
68
+ * @format uri
69
+ */
70
+ url: string;
71
+
72
+ /**
73
+ * An optional string describing the target server.
74
+ */
75
+ description?: string;
76
+ }
77
+
78
+ export interface IExternalDocs {
79
+ /**
80
+ * The URL for target documentation.
81
+ *
82
+ * @format uri
83
+ */
84
+ url: string;
85
+
86
+ /**
87
+ * A short description of the target documentation.
88
+ */
89
+ description?: string;
90
+ }
91
+ }
@@ -1,29 +1,29 @@
1
- import { IJsonComponents } from "typia";
2
-
3
- import { ISwaggerSecurityScheme } from "./ISwaggerSecurityScheme";
4
-
5
- /**
6
- * Reusable components in Swagger.
7
- *
8
- * `ISwaggerComponents` is a data structure representing content of `components` object
9
- * in `swagger.json` file generated by Nestia. Note that, this is not an universal
10
- * structure, but a dedicated structure only for Nestia.
11
- *
12
- * @author Jeongho Nam - https://github.com/samchon
13
- */
14
- export interface ISwaggerComponents {
15
- /**
16
- * An object to hold reusable DTO schemas.
17
- *
18
- * For reference, `nestia` stores every object and alias types as reusable DTO
19
- * schemas. The alias type means that defined by `type` keyword in TypeScript.
20
- */
21
- schemas?: Record<string, IJsonComponents.IAlias>;
22
-
23
- /**
24
- * An object to hold reusable security schemes.
25
- *
26
- * This property be configured by user in `nestia.config.ts` file.
27
- */
28
- securitySchemes?: Record<string, ISwaggerSecurityScheme>;
29
- }
1
+ import { IJsonComponents } from "typia";
2
+
3
+ import { ISwaggerSecurityScheme } from "./ISwaggerSecurityScheme";
4
+
5
+ /**
6
+ * Reusable components in Swagger.
7
+ *
8
+ * `ISwaggerComponents` is a data structure representing content of `components` object
9
+ * in `swagger.json` file generated by Nestia. Note that, this is not an universal
10
+ * structure, but a dedicated structure only for Nestia.
11
+ *
12
+ * @author Jeongho Nam - https://github.com/samchon
13
+ */
14
+ export interface ISwaggerComponents {
15
+ /**
16
+ * An object to hold reusable DTO schemas.
17
+ *
18
+ * For reference, `nestia` stores every object and alias types as reusable DTO
19
+ * schemas. The alias type means that defined by `type` keyword in TypeScript.
20
+ */
21
+ schemas?: Record<string, IJsonComponents.IAlias>;
22
+
23
+ /**
24
+ * An object to hold reusable security schemes.
25
+ *
26
+ * This property be configured by user in `nestia.config.ts` file.
27
+ */
28
+ securitySchemes?: Record<string, ISwaggerSecurityScheme>;
29
+ }
@@ -1,80 +1,80 @@
1
- /**
2
- * Information about the API.
3
- *
4
- * @author Samchon
5
- */
6
- export interface ISwaggerInfo {
7
- /**
8
- * The title of the API.
9
- */
10
- title: string;
11
-
12
- /**
13
- * A short description of the API.
14
- */
15
- description?: string;
16
-
17
- /**
18
- * A URL to the Terms of Service for the API.
19
- *
20
- * @format uri
21
- */
22
- termsOfService?: string;
23
-
24
- /**
25
- * The contact information for the exposed API.
26
- */
27
- contact?: ISwaggerInfo.IContact;
28
-
29
- /**
30
- * The license information for the exposed API.
31
- */
32
- license?: ISwaggerInfo.ILicense;
33
-
34
- /**
35
- * Version of the API.
36
- */
37
- version: string;
38
- }
39
- export namespace ISwaggerInfo {
40
- /**
41
- * Contact information for the exposed API.
42
- */
43
- export interface IContact {
44
- /**
45
- * The identifying name of the contact person/organization.
46
- */
47
- name?: string;
48
-
49
- /**
50
- * The URL pointing to the contact information.
51
- *
52
- * @format uri
53
- */
54
- url?: string;
55
-
56
- /**
57
- * The email address of the contact person/organization.
58
- *
59
- * @format email
60
- */
61
- email?: string;
62
- }
63
-
64
- /**
65
- * License information for the exposed API.
66
- */
67
- export interface ILicense {
68
- /**
69
- * The license name used for the API.
70
- */
71
- name: string;
72
-
73
- /**
74
- * A URL to the license used for the API.
75
- *
76
- * @format uri
77
- */
78
- url?: string;
79
- }
80
- }
1
+ /**
2
+ * Information about the API.
3
+ *
4
+ * @author Samchon
5
+ */
6
+ export interface ISwaggerInfo {
7
+ /**
8
+ * The title of the API.
9
+ */
10
+ title: string;
11
+
12
+ /**
13
+ * A short description of the API.
14
+ */
15
+ description?: string;
16
+
17
+ /**
18
+ * A URL to the Terms of Service for the API.
19
+ *
20
+ * @format uri
21
+ */
22
+ termsOfService?: string;
23
+
24
+ /**
25
+ * The contact information for the exposed API.
26
+ */
27
+ contact?: ISwaggerInfo.IContact;
28
+
29
+ /**
30
+ * The license information for the exposed API.
31
+ */
32
+ license?: ISwaggerInfo.ILicense;
33
+
34
+ /**
35
+ * Version of the API.
36
+ */
37
+ version: string;
38
+ }
39
+ export namespace ISwaggerInfo {
40
+ /**
41
+ * Contact information for the exposed API.
42
+ */
43
+ export interface IContact {
44
+ /**
45
+ * The identifying name of the contact person/organization.
46
+ */
47
+ name?: string;
48
+
49
+ /**
50
+ * The URL pointing to the contact information.
51
+ *
52
+ * @format uri
53
+ */
54
+ url?: string;
55
+
56
+ /**
57
+ * The email address of the contact person/organization.
58
+ *
59
+ * @format email
60
+ */
61
+ email?: string;
62
+ }
63
+
64
+ /**
65
+ * License information for the exposed API.
66
+ */
67
+ export interface ILicense {
68
+ /**
69
+ * The license name used for the API.
70
+ */
71
+ name: string;
72
+
73
+ /**
74
+ * A URL to the license used for the API.
75
+ *
76
+ * @format uri
77
+ */
78
+ url?: string;
79
+ }
80
+ }