@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,27 +1,27 @@
1
- import { IValidation } from "typia";
2
-
3
- export interface IRequestFormDataProps<T> {
4
- files: Array<IRequestFormDataProps.IFile>;
5
- validator:
6
- | IRequestFormDataProps.IAssert<T>
7
- | IRequestFormDataProps.IIs<T>
8
- | IRequestFormDataProps.IValidate<T>;
9
- }
10
- export namespace IRequestFormDataProps {
11
- export interface IAssert<T> {
12
- type: "assert";
13
- assert: (input: FormData) => T;
14
- }
15
- export interface IIs<T> {
16
- type: "is";
17
- is: (input: FormData) => T | null;
18
- }
19
- export interface IValidate<T> {
20
- type: "validate";
21
- validate: (input: FormData) => IValidation<T>;
22
- }
23
- export interface IFile {
24
- name: string;
25
- limit: number | null;
26
- }
27
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export interface IRequestFormDataProps<T> {
4
+ files: Array<IRequestFormDataProps.IFile>;
5
+ validator:
6
+ | IRequestFormDataProps.IAssert<T>
7
+ | IRequestFormDataProps.IIs<T>
8
+ | IRequestFormDataProps.IValidate<T>;
9
+ }
10
+ export namespace IRequestFormDataProps {
11
+ export interface IAssert<T> {
12
+ type: "assert";
13
+ assert: (input: FormData) => T;
14
+ }
15
+ export interface IIs<T> {
16
+ type: "is";
17
+ is: (input: FormData) => T | null;
18
+ }
19
+ export interface IValidate<T> {
20
+ type: "validate";
21
+ validate: (input: FormData) => IValidation<T>;
22
+ }
23
+ export interface IFile {
24
+ name: string;
25
+ limit: number | null;
26
+ }
27
+ }
@@ -1,52 +1,52 @@
1
- import ts from "typescript";
2
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
3
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
4
- import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
5
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
- import { TransformerError } from "typia/lib/transformers/TransformerError";
7
-
8
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
9
-
10
- export namespace PlainBodyProgrammer {
11
- export const generate =
12
- (project: INestiaTransformProject) =>
13
- (modulo: ts.LeftHandSideExpression) =>
14
- (type: ts.Type): ts.Expression => {
15
- const result = MetadataFactory.analyze(project.checker)({
16
- escape: false,
17
- constant: true,
18
- absorb: true,
19
- validate,
20
- })(new MetadataCollection())(type);
21
- if (result.success === false)
22
- throw TransformerError.from("nestia.core.TypedParam")(result.errors);
23
- return AssertProgrammer.write({
24
- ...project,
25
- options: {
26
- numeric: false,
27
- finite: false,
28
- functional: false,
29
- },
30
- })(modulo)(false)(type);
31
- };
32
- }
33
-
34
- const validate = (metadata: Metadata): string[] => {
35
- const errors: string[] = [];
36
- const insert = (msg: string) => errors.push(msg);
37
-
38
- const expected: number =
39
- (metadata.atomics.some((a) => a.type === "string") ? 1 : 0) +
40
- metadata.templates.length +
41
- metadata.constants
42
- .filter((c) => c.type === "string")
43
- .map((c) => c.values.length)
44
- .reduce((a, b) => a + b, 0);
45
- if (expected === 0 || expected !== metadata.size())
46
- insert(`only string type is allowed`);
47
- if (metadata.isRequired() === false) insert(`do not allow undefindable type`);
48
- if (metadata.nullable === true) insert(`do not allow nullable type`);
49
- else if (metadata.any === true) insert(`do not allow any type`);
50
-
51
- return errors;
52
- };
1
+ import ts from "typescript";
2
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
3
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
4
+ import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
5
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
+ import { TransformerError } from "typia/lib/transformers/TransformerError";
7
+
8
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
9
+
10
+ export namespace PlainBodyProgrammer {
11
+ export const generate =
12
+ (project: INestiaTransformProject) =>
13
+ (modulo: ts.LeftHandSideExpression) =>
14
+ (type: ts.Type): ts.Expression => {
15
+ const result = MetadataFactory.analyze(project.checker)({
16
+ escape: false,
17
+ constant: true,
18
+ absorb: true,
19
+ validate,
20
+ })(new MetadataCollection())(type);
21
+ if (result.success === false)
22
+ throw TransformerError.from("nestia.core.TypedParam")(result.errors);
23
+ return AssertProgrammer.write({
24
+ ...project,
25
+ options: {
26
+ numeric: false,
27
+ finite: false,
28
+ functional: false,
29
+ },
30
+ })(modulo)(false)(type);
31
+ };
32
+ }
33
+
34
+ const validate = (metadata: Metadata): string[] => {
35
+ const errors: string[] = [];
36
+ const insert = (msg: string) => errors.push(msg);
37
+
38
+ const expected: number =
39
+ (metadata.atomics.some((a) => a.type === "string") ? 1 : 0) +
40
+ metadata.templates.length +
41
+ metadata.constants
42
+ .filter((c) => c.type === "string")
43
+ .map((c) => c.values.length)
44
+ .reduce((a, b) => a + b, 0);
45
+ if (expected === 0 || expected !== metadata.size())
46
+ insert(`only string type is allowed`);
47
+ if (metadata.isRequired() === false) insert(`do not allow undefindable type`);
48
+ if (metadata.nullable === true) insert(`do not allow nullable type`);
49
+ else if (metadata.any === true) insert(`do not allow any type`);
50
+
51
+ return errors;
52
+ };
@@ -1,71 +1,71 @@
1
- import ts from "typescript";
2
- import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
3
- import { TypeFactory } from "typia/lib/factories/TypeFactory";
4
- import { TransformerError } from "typia/lib/transformers/TransformerError";
5
-
6
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
7
-
8
- export namespace TypedExceptionProgrammer {
9
- export const generate =
10
- ({ checker }: INestiaTransformProject) =>
11
- (expression: ts.CallExpression): ts.CallExpression => {
12
- // CHECK GENERIC ARGUMENT EXISTENCE
13
- if (!expression.typeArguments?.[0])
14
- throw TransformerError.from("nestia.core.TypedException")([
15
- {
16
- name: "uknown",
17
- messages: [NOT_SPECIFIED],
18
- explore: {
19
- top: true,
20
- object: null,
21
- property: null,
22
- nested: null,
23
- escaped: false,
24
- aliased: false,
25
- },
26
- },
27
- ]);
28
- // CHECK DUPLICATED TRNASFORMATION
29
- else if (expression.arguments.length === 3) return expression;
30
-
31
- // GET TYPE INFO
32
- const node: ts.TypeNode = expression.typeArguments[0];
33
- const type: ts.Type = checker.getTypeFromTypeNode(node);
34
-
35
- // VALIDATE TYPE
36
- if (type.isTypeParameter())
37
- throw TransformerError.from("nestia.core.TypedException")([
38
- {
39
- name: TypeFactory.getFullName(checker)(type),
40
- messages: [NO_GENERIC_ARGUMENT],
41
- explore: {
42
- top: true,
43
- object: null,
44
- property: null,
45
- nested: null,
46
- escaped: false,
47
- aliased: false,
48
- },
49
- },
50
- ]);
51
- JsonMetadataFactory.analyze("@nestia.core.TypedException")(checker)(type);
52
-
53
- // DO TRANSFORM
54
- const name: string = TypeFactory.getFullName(checker)(type);
55
- return ts.factory.updateCallExpression(
56
- expression,
57
- expression.expression,
58
- expression.typeArguments,
59
- [
60
- expression.arguments[0],
61
- expression.arguments[1] ?? ts.factory.createIdentifier("undefined"),
62
- ts.factory.createStringLiteral(name),
63
- ],
64
- );
65
- };
66
- }
67
-
68
- const NOT_SPECIFIED =
69
- "Error on @nestia.core.TypedException(): generic argument is not specified.";
70
- const NO_GENERIC_ARGUMENT =
71
- "Error on @nestia.core.TypedException(): non-specified generic argument.";
1
+ import ts from "typescript";
2
+ import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
3
+ import { TypeFactory } from "typia/lib/factories/TypeFactory";
4
+ import { TransformerError } from "typia/lib/transformers/TransformerError";
5
+
6
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
7
+
8
+ export namespace TypedExceptionProgrammer {
9
+ export const generate =
10
+ ({ checker }: INestiaTransformProject) =>
11
+ (expression: ts.CallExpression): ts.CallExpression => {
12
+ // CHECK GENERIC ARGUMENT EXISTENCE
13
+ if (!expression.typeArguments?.[0])
14
+ throw TransformerError.from("nestia.core.TypedException")([
15
+ {
16
+ name: "uknown",
17
+ messages: [NOT_SPECIFIED],
18
+ explore: {
19
+ top: true,
20
+ object: null,
21
+ property: null,
22
+ nested: null,
23
+ escaped: false,
24
+ aliased: false,
25
+ },
26
+ },
27
+ ]);
28
+ // CHECK DUPLICATED TRNASFORMATION
29
+ else if (expression.arguments.length === 3) return expression;
30
+
31
+ // GET TYPE INFO
32
+ const node: ts.TypeNode = expression.typeArguments[0];
33
+ const type: ts.Type = checker.getTypeFromTypeNode(node);
34
+
35
+ // VALIDATE TYPE
36
+ if (type.isTypeParameter())
37
+ throw TransformerError.from("nestia.core.TypedException")([
38
+ {
39
+ name: TypeFactory.getFullName(checker)(type),
40
+ messages: [NO_GENERIC_ARGUMENT],
41
+ explore: {
42
+ top: true,
43
+ object: null,
44
+ property: null,
45
+ nested: null,
46
+ escaped: false,
47
+ aliased: false,
48
+ },
49
+ },
50
+ ]);
51
+ JsonMetadataFactory.analyze("@nestia.core.TypedException")(checker)(type);
52
+
53
+ // DO TRANSFORM
54
+ const name: string = TypeFactory.getFullName(checker)(type);
55
+ return ts.factory.updateCallExpression(
56
+ expression,
57
+ expression.expression,
58
+ expression.typeArguments,
59
+ [
60
+ expression.arguments[0],
61
+ expression.arguments[1] ?? ts.factory.createIdentifier("undefined"),
62
+ ts.factory.createStringLiteral(name),
63
+ ],
64
+ );
65
+ };
66
+ }
67
+
68
+ const NOT_SPECIFIED =
69
+ "Error on @nestia.core.TypedException(): generic argument is not specified.";
70
+ const NO_GENERIC_ARGUMENT =
71
+ "Error on @nestia.core.TypedException(): non-specified generic argument.";
@@ -1,108 +1,108 @@
1
- import ts from "typescript";
2
- import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
3
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
- import { HttpAssertFormDataProgrammer } from "typia/lib/programmers/http/HttpAssertFormDataProgrammer";
6
- import { HttpFormDataProgrammer } from "typia/lib/programmers/http/HttpFormDataProgrammer";
7
- import { HttpIsFormDataProgrammer } from "typia/lib/programmers/http/HttpIsFormDataProgrammer";
8
- import { HttpValidateFormDataProgrammer } from "typia/lib/programmers/http/HttpValidateFormDataProgrammer";
9
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
10
- import { IProject } from "typia/lib/transformers/IProject";
11
- import { TransformerError } from "typia/lib/transformers/TransformerError";
12
-
13
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
14
- import { IRequestFormDataProps } from "../options/IRequestFormDataProps";
15
-
16
- export namespace TypedFormDataBodyProgrammer {
17
- export const generate =
18
- (project: INestiaTransformProject) =>
19
- (modulo: ts.LeftHandSideExpression) =>
20
- (type: ts.Type): ts.ObjectLiteralExpression => {
21
- // VALIDATE TYPE
22
- const collection: MetadataCollection = new MetadataCollection();
23
- const result = MetadataFactory.analyze(
24
- project.checker,
25
- project.context,
26
- )({
27
- escape: false,
28
- constant: true,
29
- absorb: true,
30
- validate: HttpFormDataProgrammer.validate,
31
- })(collection)(type);
32
- if (result.success === false)
33
- throw TransformerError.from("nestia.core.TypedFormData.Body")(
34
- result.errors,
35
- );
36
-
37
- const files: IRequestFormDataProps.IFile[] =
38
- result.data.objects[0].properties
39
- .filter(
40
- (p) =>
41
- isFile(p.value) ||
42
- p.value.arrays.some((a) => isFile(a.type.value)),
43
- )
44
- .map((p) => ({
45
- name: p.key.constants[0].values[0] as string,
46
- limit: !!p.value.natives.length ? 1 : null,
47
- }));
48
-
49
- // GENERATE VALIDATION PLAN
50
- const parameter =
51
- (key: IRequestFormDataProps<any>["validator"]["type"]) =>
52
- (
53
- programmer: (
54
- project: IProject,
55
- ) => (
56
- modulo: ts.LeftHandSideExpression,
57
- ) => (type: ts.Type) => ts.ArrowFunction,
58
- ) =>
59
- ts.factory.createObjectLiteralExpression(
60
- [
61
- ts.factory.createPropertyAssignment(
62
- ts.factory.createIdentifier("files"),
63
- LiteralFactory.generate(files),
64
- ),
65
- ts.factory.createPropertyAssignment(
66
- ts.factory.createIdentifier("validator"),
67
- ts.factory.createObjectLiteralExpression(
68
- [
69
- ts.factory.createPropertyAssignment(
70
- ts.factory.createIdentifier("type"),
71
- ts.factory.createStringLiteral(key),
72
- ),
73
- ts.factory.createPropertyAssignment(
74
- ts.factory.createIdentifier(key),
75
- programmer({
76
- ...project,
77
- options: {
78
- numeric: false,
79
- finite: false,
80
- functional: false,
81
- },
82
- })(modulo)(type),
83
- ),
84
- ],
85
- true,
86
- ),
87
- ),
88
- ],
89
- true,
90
- );
91
-
92
- // RETURNS
93
- const category = project.options.validate;
94
- if (category === "is" || category === "equals")
95
- return parameter("is")(HttpIsFormDataProgrammer.write);
96
- else if (
97
- category === "validate" ||
98
- category === "validateEquals" ||
99
- category === "validateClone" ||
100
- category === "validatePrune"
101
- )
102
- return parameter("validate")(HttpValidateFormDataProgrammer.write);
103
- return parameter("assert")(HttpAssertFormDataProgrammer.write);
104
- };
105
- }
106
-
107
- const isFile = (meta: Metadata) =>
108
- meta.natives.some((n) => n === "File" || n === "Blob");
1
+ import ts from "typescript";
2
+ import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
3
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
+ import { HttpAssertFormDataProgrammer } from "typia/lib/programmers/http/HttpAssertFormDataProgrammer";
6
+ import { HttpFormDataProgrammer } from "typia/lib/programmers/http/HttpFormDataProgrammer";
7
+ import { HttpIsFormDataProgrammer } from "typia/lib/programmers/http/HttpIsFormDataProgrammer";
8
+ import { HttpValidateFormDataProgrammer } from "typia/lib/programmers/http/HttpValidateFormDataProgrammer";
9
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
10
+ import { IProject } from "typia/lib/transformers/IProject";
11
+ import { TransformerError } from "typia/lib/transformers/TransformerError";
12
+
13
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
14
+ import { IRequestFormDataProps } from "../options/IRequestFormDataProps";
15
+
16
+ export namespace TypedFormDataBodyProgrammer {
17
+ export const generate =
18
+ (project: INestiaTransformProject) =>
19
+ (modulo: ts.LeftHandSideExpression) =>
20
+ (type: ts.Type): ts.ObjectLiteralExpression => {
21
+ // VALIDATE TYPE
22
+ const collection: MetadataCollection = new MetadataCollection();
23
+ const result = MetadataFactory.analyze(
24
+ project.checker,
25
+ project.context,
26
+ )({
27
+ escape: false,
28
+ constant: true,
29
+ absorb: true,
30
+ validate: HttpFormDataProgrammer.validate,
31
+ })(collection)(type);
32
+ if (result.success === false)
33
+ throw TransformerError.from("nestia.core.TypedFormData.Body")(
34
+ result.errors,
35
+ );
36
+
37
+ const files: IRequestFormDataProps.IFile[] =
38
+ result.data.objects[0].properties
39
+ .filter(
40
+ (p) =>
41
+ isFile(p.value) ||
42
+ p.value.arrays.some((a) => isFile(a.type.value)),
43
+ )
44
+ .map((p) => ({
45
+ name: p.key.constants[0].values[0] as string,
46
+ limit: !!p.value.natives.length ? 1 : null,
47
+ }));
48
+
49
+ // GENERATE VALIDATION PLAN
50
+ const parameter =
51
+ (key: IRequestFormDataProps<any>["validator"]["type"]) =>
52
+ (
53
+ programmer: (
54
+ project: IProject,
55
+ ) => (
56
+ modulo: ts.LeftHandSideExpression,
57
+ ) => (type: ts.Type) => ts.ArrowFunction,
58
+ ) =>
59
+ ts.factory.createObjectLiteralExpression(
60
+ [
61
+ ts.factory.createPropertyAssignment(
62
+ ts.factory.createIdentifier("files"),
63
+ LiteralFactory.generate(files),
64
+ ),
65
+ ts.factory.createPropertyAssignment(
66
+ ts.factory.createIdentifier("validator"),
67
+ ts.factory.createObjectLiteralExpression(
68
+ [
69
+ ts.factory.createPropertyAssignment(
70
+ ts.factory.createIdentifier("type"),
71
+ ts.factory.createStringLiteral(key),
72
+ ),
73
+ ts.factory.createPropertyAssignment(
74
+ ts.factory.createIdentifier(key),
75
+ programmer({
76
+ ...project,
77
+ options: {
78
+ numeric: false,
79
+ finite: false,
80
+ functional: false,
81
+ },
82
+ })(modulo)(type),
83
+ ),
84
+ ],
85
+ true,
86
+ ),
87
+ ),
88
+ ],
89
+ true,
90
+ );
91
+
92
+ // RETURNS
93
+ const category = project.options.validate;
94
+ if (category === "is" || category === "equals")
95
+ return parameter("is")(HttpIsFormDataProgrammer.write);
96
+ else if (
97
+ category === "validate" ||
98
+ category === "validateEquals" ||
99
+ category === "validateClone" ||
100
+ category === "validatePrune"
101
+ )
102
+ return parameter("validate")(HttpValidateFormDataProgrammer.write);
103
+ return parameter("assert")(HttpAssertFormDataProgrammer.write);
104
+ };
105
+ }
106
+
107
+ const isFile = (meta: Metadata) =>
108
+ meta.natives.some((n) => n === "File" || n === "Blob");