@nestia/core 11.0.0-dev.20260316 → 11.0.0

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 (47) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/lib/decorators/NoTransformConfigurationError.d.ts +1 -24
  4. package/lib/decorators/NoTransformConfigurationError.js +2 -0
  5. package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
  6. package/lib/decorators/doNotThrowTransformError.d.ts +1 -0
  7. package/lib/decorators/doNotThrowTransformError.js +9 -0
  8. package/lib/decorators/doNotThrowTransformError.js.map +1 -0
  9. package/lib/module.d.ts +1 -1
  10. package/lib/module.js +1 -1
  11. package/lib/module.js.map +1 -1
  12. package/package.json +8 -8
  13. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  14. package/src/decorators/EncryptedBody.ts +96 -96
  15. package/src/decorators/EncryptedController.ts +40 -40
  16. package/src/decorators/EncryptedModule.ts +98 -98
  17. package/src/decorators/EncryptedRoute.ts +212 -212
  18. package/src/decorators/HumanRoute.ts +21 -21
  19. package/src/decorators/NoTransformConfigurationError.ts +37 -34
  20. package/src/decorators/SwaggerCustomizer.ts +97 -97
  21. package/src/decorators/TypedFormData.ts +187 -187
  22. package/src/decorators/TypedRoute.ts +196 -196
  23. package/src/decorators/doNotThrowTransformError.ts +5 -0
  24. package/src/decorators/internal/headers_to_object.ts +11 -11
  25. package/src/module.ts +23 -23
  26. package/src/options/INestiaTransformOptions.ts +34 -34
  27. package/src/options/INestiaTransformProject.ts +10 -10
  28. package/src/programmers/PlainBodyProgrammer.ts +72 -72
  29. package/src/programmers/TypedBodyProgrammer.ts +148 -148
  30. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  31. package/src/programmers/TypedHeadersProgrammer.ts +65 -65
  32. package/src/programmers/TypedParamProgrammer.ts +33 -33
  33. package/src/programmers/TypedQueryBodyProgrammer.ts +113 -113
  34. package/src/programmers/TypedQueryProgrammer.ts +115 -115
  35. package/src/programmers/TypedQueryRouteProgrammer.ts +107 -107
  36. package/src/programmers/TypedRouteProgrammer.ts +103 -103
  37. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +74 -74
  38. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +77 -77
  39. package/src/programmers/http/HttpQuerifyProgrammer.ts +110 -110
  40. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +78 -78
  41. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  42. package/src/transform.ts +35 -35
  43. package/src/transformers/FileTransformer.ts +109 -109
  44. package/src/transformers/MethodTransformer.ts +103 -103
  45. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  46. package/src/transformers/TypedRouteTransformer.ts +85 -85
  47. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
@@ -1,77 +1,77 @@
1
- import {
2
- ITypiaContext,
3
- IdentifierFactory,
4
- IsProgrammer,
5
- StatementFactory,
6
- } from "@typia/core";
7
- import ts from "typescript";
8
-
9
- import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
10
-
11
- export namespace HttpIsQuerifyProgrammer {
12
- export const write = (props: {
13
- context: ITypiaContext;
14
- modulo: ts.LeftHandSideExpression;
15
- type: ts.Type;
16
- }): ts.ArrowFunction =>
17
- ts.factory.createArrowFunction(
18
- undefined,
19
- undefined,
20
- [IdentifierFactory.parameter("input")],
21
- undefined,
22
- undefined,
23
- ts.factory.createBlock([
24
- StatementFactory.constant({
25
- name: "is",
26
- value: IsProgrammer.write({
27
- config: {
28
- equals: false,
29
- },
30
- context: {
31
- ...props.context,
32
- options: {
33
- ...props.context.options,
34
- functional: false,
35
- numeric: false,
36
- },
37
- },
38
- modulo: props.modulo,
39
- type: props.type,
40
- name: undefined,
41
- }),
42
- }),
43
- StatementFactory.constant({
44
- name: "stringify",
45
- value: HttpQuerifyProgrammer.write({
46
- context: {
47
- ...props.context,
48
- options: {
49
- ...props.context.options,
50
- functional: false,
51
- numeric: false,
52
- },
53
- },
54
- modulo: props.modulo,
55
- type: props.type,
56
- }),
57
- }),
58
- ts.factory.createReturnStatement(
59
- ts.factory.createConditionalExpression(
60
- ts.factory.createCallExpression(
61
- ts.factory.createIdentifier("is"),
62
- undefined,
63
- [ts.factory.createIdentifier("input")],
64
- ),
65
- undefined,
66
- ts.factory.createCallExpression(
67
- ts.factory.createIdentifier("stringify"),
68
- undefined,
69
- [ts.factory.createIdentifier("input")],
70
- ),
71
- undefined,
72
- ts.factory.createNull(),
73
- ),
74
- ),
75
- ]),
76
- );
77
- }
1
+ import {
2
+ ITypiaContext,
3
+ IdentifierFactory,
4
+ IsProgrammer,
5
+ StatementFactory,
6
+ } from "@typia/core";
7
+ import ts from "typescript";
8
+
9
+ import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
10
+
11
+ export namespace HttpIsQuerifyProgrammer {
12
+ export const write = (props: {
13
+ context: ITypiaContext;
14
+ modulo: ts.LeftHandSideExpression;
15
+ type: ts.Type;
16
+ }): ts.ArrowFunction =>
17
+ ts.factory.createArrowFunction(
18
+ undefined,
19
+ undefined,
20
+ [IdentifierFactory.parameter("input")],
21
+ undefined,
22
+ undefined,
23
+ ts.factory.createBlock([
24
+ StatementFactory.constant({
25
+ name: "is",
26
+ value: IsProgrammer.write({
27
+ config: {
28
+ equals: false,
29
+ },
30
+ context: {
31
+ ...props.context,
32
+ options: {
33
+ ...props.context.options,
34
+ functional: false,
35
+ numeric: false,
36
+ },
37
+ },
38
+ modulo: props.modulo,
39
+ type: props.type,
40
+ name: undefined,
41
+ }),
42
+ }),
43
+ StatementFactory.constant({
44
+ name: "stringify",
45
+ value: HttpQuerifyProgrammer.write({
46
+ context: {
47
+ ...props.context,
48
+ options: {
49
+ ...props.context.options,
50
+ functional: false,
51
+ numeric: false,
52
+ },
53
+ },
54
+ modulo: props.modulo,
55
+ type: props.type,
56
+ }),
57
+ }),
58
+ ts.factory.createReturnStatement(
59
+ ts.factory.createConditionalExpression(
60
+ ts.factory.createCallExpression(
61
+ ts.factory.createIdentifier("is"),
62
+ undefined,
63
+ [ts.factory.createIdentifier("input")],
64
+ ),
65
+ undefined,
66
+ ts.factory.createCallExpression(
67
+ ts.factory.createIdentifier("stringify"),
68
+ undefined,
69
+ [ts.factory.createIdentifier("input")],
70
+ ),
71
+ undefined,
72
+ ts.factory.createNull(),
73
+ ),
74
+ ),
75
+ ]),
76
+ );
77
+ }
@@ -1,110 +1,110 @@
1
- import {
2
- FunctionProgrammer,
3
- HttpQueryProgrammer,
4
- ITypiaContext,
5
- IdentifierFactory,
6
- MetadataCollection,
7
- MetadataFactory,
8
- MetadataObject,
9
- MetadataSchema,
10
- StatementFactory,
11
- TransformerError,
12
- } from "@typia/core";
13
- import ts from "typescript";
14
-
15
- export namespace HttpQuerifyProgrammer {
16
- export const write = (props: {
17
- context: ITypiaContext;
18
- modulo: ts.LeftHandSideExpression;
19
- type: ts.Type;
20
- }): ts.ArrowFunction => {
21
- // GET OBJECT TYPE
22
- const functor: FunctionProgrammer = new FunctionProgrammer(
23
- props.modulo.getText(),
24
- );
25
- const storage: MetadataCollection = new MetadataCollection();
26
- const result = MetadataFactory.analyze({
27
- checker: props.context.checker,
28
- transformer: props.context.transformer,
29
- options: {
30
- escape: false,
31
- constant: true,
32
- absorb: true,
33
- validate: HttpQueryProgrammer.validate,
34
- },
35
- type: props.type,
36
- components: storage,
37
- });
38
- if (result.success === false)
39
- throw TransformerError.from({
40
- code: functor.method,
41
- errors: result.errors,
42
- });
43
-
44
- const object: MetadataObject = result.data.objects[0]!;
45
- return ts.factory.createArrowFunction(
46
- undefined,
47
- undefined,
48
- [IdentifierFactory.parameter("input")],
49
- undefined,
50
- undefined,
51
- ts.factory.createBlock(
52
- [
53
- ...functor.declare(),
54
- StatementFactory.constant({
55
- name: "output",
56
- value: ts.factory.createNewExpression(
57
- ts.factory.createIdentifier("URLSearchParams"),
58
- undefined,
59
- [],
60
- ),
61
- }),
62
- ...object.type.properties.map((p) =>
63
- ts.factory.createExpressionStatement(
64
- decode(p.key.constants[0]!.values[0]!.value as string)(p.value),
65
- ),
66
- ),
67
- ts.factory.createReturnStatement(
68
- ts.factory.createIdentifier("output"),
69
- ),
70
- ],
71
- true,
72
- ),
73
- );
74
- };
75
-
76
- const decode =
77
- (key: string) =>
78
- (value: MetadataSchema): ts.CallExpression =>
79
- !!value.arrays.length
80
- ? ts.factory.createCallExpression(
81
- IdentifierFactory.access(
82
- IdentifierFactory.access(
83
- ts.factory.createIdentifier("input"),
84
- key,
85
- ),
86
- "forEach",
87
- ),
88
- undefined,
89
- [
90
- ts.factory.createArrowFunction(
91
- undefined,
92
- undefined,
93
- [IdentifierFactory.parameter("elem")],
94
- undefined,
95
- undefined,
96
- append(key)(ts.factory.createIdentifier("elem")),
97
- ),
98
- ],
99
- )
100
- : append(key)(
101
- IdentifierFactory.access(ts.factory.createIdentifier("input"), key),
102
- );
103
-
104
- const append = (key: string) => (elem: ts.Expression) =>
105
- ts.factory.createCallExpression(
106
- IdentifierFactory.access(ts.factory.createIdentifier("output"), "append"),
107
- undefined,
108
- [ts.factory.createStringLiteral(key), elem],
109
- );
110
- }
1
+ import {
2
+ FunctionProgrammer,
3
+ HttpQueryProgrammer,
4
+ ITypiaContext,
5
+ IdentifierFactory,
6
+ MetadataCollection,
7
+ MetadataFactory,
8
+ MetadataObject,
9
+ MetadataSchema,
10
+ StatementFactory,
11
+ TransformerError,
12
+ } from "@typia/core";
13
+ import ts from "typescript";
14
+
15
+ export namespace HttpQuerifyProgrammer {
16
+ export const write = (props: {
17
+ context: ITypiaContext;
18
+ modulo: ts.LeftHandSideExpression;
19
+ type: ts.Type;
20
+ }): ts.ArrowFunction => {
21
+ // GET OBJECT TYPE
22
+ const functor: FunctionProgrammer = new FunctionProgrammer(
23
+ props.modulo.getText(),
24
+ );
25
+ const storage: MetadataCollection = new MetadataCollection();
26
+ const result = MetadataFactory.analyze({
27
+ checker: props.context.checker,
28
+ transformer: props.context.transformer,
29
+ options: {
30
+ escape: false,
31
+ constant: true,
32
+ absorb: true,
33
+ validate: HttpQueryProgrammer.validate,
34
+ },
35
+ type: props.type,
36
+ components: storage,
37
+ });
38
+ if (result.success === false)
39
+ throw TransformerError.from({
40
+ code: functor.method,
41
+ errors: result.errors,
42
+ });
43
+
44
+ const object: MetadataObject = result.data.objects[0]!;
45
+ return ts.factory.createArrowFunction(
46
+ undefined,
47
+ undefined,
48
+ [IdentifierFactory.parameter("input")],
49
+ undefined,
50
+ undefined,
51
+ ts.factory.createBlock(
52
+ [
53
+ ...functor.declare(),
54
+ StatementFactory.constant({
55
+ name: "output",
56
+ value: ts.factory.createNewExpression(
57
+ ts.factory.createIdentifier("URLSearchParams"),
58
+ undefined,
59
+ [],
60
+ ),
61
+ }),
62
+ ...object.type.properties.map((p) =>
63
+ ts.factory.createExpressionStatement(
64
+ decode(p.key.constants[0]!.values[0]!.value as string)(p.value),
65
+ ),
66
+ ),
67
+ ts.factory.createReturnStatement(
68
+ ts.factory.createIdentifier("output"),
69
+ ),
70
+ ],
71
+ true,
72
+ ),
73
+ );
74
+ };
75
+
76
+ const decode =
77
+ (key: string) =>
78
+ (value: MetadataSchema): ts.CallExpression =>
79
+ !!value.arrays.length
80
+ ? ts.factory.createCallExpression(
81
+ IdentifierFactory.access(
82
+ IdentifierFactory.access(
83
+ ts.factory.createIdentifier("input"),
84
+ key,
85
+ ),
86
+ "forEach",
87
+ ),
88
+ undefined,
89
+ [
90
+ ts.factory.createArrowFunction(
91
+ undefined,
92
+ undefined,
93
+ [IdentifierFactory.parameter("elem")],
94
+ undefined,
95
+ undefined,
96
+ append(key)(ts.factory.createIdentifier("elem")),
97
+ ),
98
+ ],
99
+ )
100
+ : append(key)(
101
+ IdentifierFactory.access(ts.factory.createIdentifier("input"), key),
102
+ );
103
+
104
+ const append = (key: string) => (elem: ts.Expression) =>
105
+ ts.factory.createCallExpression(
106
+ IdentifierFactory.access(ts.factory.createIdentifier("output"), "append"),
107
+ undefined,
108
+ [ts.factory.createStringLiteral(key), elem],
109
+ );
110
+ }
@@ -1,78 +1,78 @@
1
- import {
2
- ITypiaContext,
3
- IdentifierFactory,
4
- StatementFactory,
5
- ValidateProgrammer,
6
- } from "@typia/core";
7
- import ts from "typescript";
8
-
9
- import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
10
-
11
- export namespace HttpValidateQuerifyProgrammer {
12
- export const write = (props: {
13
- context: ITypiaContext;
14
- modulo: ts.LeftHandSideExpression;
15
- type: ts.Type;
16
- }): ts.ArrowFunction =>
17
- ts.factory.createArrowFunction(
18
- undefined,
19
- undefined,
20
- [IdentifierFactory.parameter("input")],
21
- undefined,
22
- undefined,
23
- ts.factory.createBlock([
24
- StatementFactory.constant({
25
- name: "validate",
26
- value: ValidateProgrammer.write({
27
- config: {
28
- equals: false,
29
- },
30
- context: {
31
- ...props.context,
32
- options: {
33
- ...props.context.options,
34
- functional: false,
35
- numeric: true,
36
- },
37
- },
38
- modulo: props.modulo,
39
- type: props.type,
40
- name: undefined,
41
- }),
42
- }),
43
- StatementFactory.constant({
44
- name: "query",
45
- value: HttpQuerifyProgrammer.write({
46
- context: {
47
- ...props.context,
48
- options: {
49
- ...props.context.options,
50
- functional: false,
51
- numeric: false,
52
- },
53
- },
54
- modulo: props.modulo,
55
- type: props.type,
56
- }),
57
- }),
58
- StatementFactory.constant({
59
- name: "output",
60
- value: ts.factory.createCallExpression(
61
- ts.factory.createIdentifier("query"),
62
- undefined,
63
- [ts.factory.createIdentifier("input")],
64
- ),
65
- }),
66
- ts.factory.createReturnStatement(
67
- ts.factory.createAsExpression(
68
- ts.factory.createCallExpression(
69
- ts.factory.createIdentifier("validate"),
70
- undefined,
71
- [ts.factory.createIdentifier("output")],
72
- ),
73
- ts.factory.createTypeReferenceNode("any"),
74
- ),
75
- ),
76
- ]),
77
- );
78
- }
1
+ import {
2
+ ITypiaContext,
3
+ IdentifierFactory,
4
+ StatementFactory,
5
+ ValidateProgrammer,
6
+ } from "@typia/core";
7
+ import ts from "typescript";
8
+
9
+ import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
10
+
11
+ export namespace HttpValidateQuerifyProgrammer {
12
+ export const write = (props: {
13
+ context: ITypiaContext;
14
+ modulo: ts.LeftHandSideExpression;
15
+ type: ts.Type;
16
+ }): ts.ArrowFunction =>
17
+ ts.factory.createArrowFunction(
18
+ undefined,
19
+ undefined,
20
+ [IdentifierFactory.parameter("input")],
21
+ undefined,
22
+ undefined,
23
+ ts.factory.createBlock([
24
+ StatementFactory.constant({
25
+ name: "validate",
26
+ value: ValidateProgrammer.write({
27
+ config: {
28
+ equals: false,
29
+ },
30
+ context: {
31
+ ...props.context,
32
+ options: {
33
+ ...props.context.options,
34
+ functional: false,
35
+ numeric: true,
36
+ },
37
+ },
38
+ modulo: props.modulo,
39
+ type: props.type,
40
+ name: undefined,
41
+ }),
42
+ }),
43
+ StatementFactory.constant({
44
+ name: "query",
45
+ value: HttpQuerifyProgrammer.write({
46
+ context: {
47
+ ...props.context,
48
+ options: {
49
+ ...props.context.options,
50
+ functional: false,
51
+ numeric: false,
52
+ },
53
+ },
54
+ modulo: props.modulo,
55
+ type: props.type,
56
+ }),
57
+ }),
58
+ StatementFactory.constant({
59
+ name: "output",
60
+ value: ts.factory.createCallExpression(
61
+ ts.factory.createIdentifier("query"),
62
+ undefined,
63
+ [ts.factory.createIdentifier("input")],
64
+ ),
65
+ }),
66
+ ts.factory.createReturnStatement(
67
+ ts.factory.createAsExpression(
68
+ ts.factory.createCallExpression(
69
+ ts.factory.createIdentifier("validate"),
70
+ undefined,
71
+ [ts.factory.createIdentifier("output")],
72
+ ),
73
+ ts.factory.createTypeReferenceNode("any"),
74
+ ),
75
+ ),
76
+ ]),
77
+ );
78
+ }
@@ -1,21 +1,21 @@
1
- import { MetadataSchema } from "@typia/core";
2
-
3
- export namespace CoreMetadataUtil {
4
- export const atomics = (
5
- meta: MetadataSchema,
6
- ): Set<"boolean" | "bigint" | "number" | "string"> =>
7
- new Set([
8
- ...meta.atomics.map((a) => a.type),
9
- ...meta.constants.map((c) => c.type),
10
- ...(meta.templates.length ? (["string"] as const) : []),
11
- ]);
12
-
13
- export const isUnion = (meta: MetadataSchema): boolean =>
14
- atomics(meta).size +
15
- meta.arrays.length +
16
- meta.tuples.length +
17
- meta.natives.length +
18
- meta.maps.length +
19
- meta.objects.length >
20
- 1;
21
- }
1
+ import { MetadataSchema } from "@typia/core";
2
+
3
+ export namespace CoreMetadataUtil {
4
+ export const atomics = (
5
+ meta: MetadataSchema,
6
+ ): Set<"boolean" | "bigint" | "number" | "string"> =>
7
+ new Set([
8
+ ...meta.atomics.map((a) => a.type),
9
+ ...meta.constants.map((c) => c.type),
10
+ ...(meta.templates.length ? (["string"] as const) : []),
11
+ ]);
12
+
13
+ export const isUnion = (meta: MetadataSchema): boolean =>
14
+ atomics(meta).size +
15
+ meta.arrays.length +
16
+ meta.tuples.length +
17
+ meta.natives.length +
18
+ meta.maps.length +
19
+ meta.objects.length >
20
+ 1;
21
+ }
package/src/transform.ts CHANGED
@@ -1,35 +1,35 @@
1
- import { ITypiaContext } from "@typia/core";
2
- import ts from "typescript";
3
-
4
- import { INestiaTransformOptions } from "./options/INestiaTransformOptions";
5
- import { FileTransformer } from "./transformers/FileTransformer";
6
-
7
- export const transform = (
8
- program: ts.Program,
9
- options: INestiaTransformOptions | undefined,
10
- extras: ITypiaContext["extras"],
11
- ): ts.TransformerFactory<ts.SourceFile> => {
12
- const compilerOptions: ts.CompilerOptions = program.getCompilerOptions();
13
- const strict: boolean =
14
- compilerOptions.strictNullChecks !== undefined
15
- ? !!compilerOptions.strictNullChecks
16
- : !!compilerOptions.strict;
17
- if (strict === false)
18
- extras.addDiagnostic({
19
- category: ts.DiagnosticCategory.Error,
20
- code: "(@nestia/core)" as any,
21
- file: undefined,
22
- start: undefined,
23
- length: undefined,
24
- messageText: "strict mode is required.",
25
- });
26
- return FileTransformer.transform({
27
- program,
28
- compilerOptions,
29
- checker: program.getTypeChecker(),
30
- printer: ts.createPrinter(),
31
- options: options ?? {},
32
- extras,
33
- });
34
- };
35
- export default transform;
1
+ import { ITypiaContext } from "@typia/core";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaTransformOptions } from "./options/INestiaTransformOptions";
5
+ import { FileTransformer } from "./transformers/FileTransformer";
6
+
7
+ export const transform = (
8
+ program: ts.Program,
9
+ options: INestiaTransformOptions | undefined,
10
+ extras: ITypiaContext["extras"],
11
+ ): ts.TransformerFactory<ts.SourceFile> => {
12
+ const compilerOptions: ts.CompilerOptions = program.getCompilerOptions();
13
+ const strict: boolean =
14
+ compilerOptions.strictNullChecks !== undefined
15
+ ? !!compilerOptions.strictNullChecks
16
+ : !!compilerOptions.strict;
17
+ if (strict === false)
18
+ extras.addDiagnostic({
19
+ category: ts.DiagnosticCategory.Error,
20
+ code: "(@nestia/core)" as any,
21
+ file: undefined,
22
+ start: undefined,
23
+ length: undefined,
24
+ messageText: "strict mode is required.",
25
+ });
26
+ return FileTransformer.transform({
27
+ program,
28
+ compilerOptions,
29
+ checker: program.getTypeChecker(),
30
+ printer: ts.createPrinter(),
31
+ options: options ?? {},
32
+ extras,
33
+ });
34
+ };
35
+ export default transform;