@nestia/core 11.0.0-dev.20260316 → 11.0.1

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,109 +1,109 @@
1
- import { ImportProgrammer, TransformerError } from "@typia/core";
2
- import ts from "typescript";
3
-
4
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
5
- import { NodeTransformer } from "./NodeTransformer";
6
-
7
- export namespace FileTransformer {
8
- export const transform =
9
- (context: Omit<INestiaTransformContext, "importer" | "transformer">) =>
10
- (transformer: ts.TransformationContext) =>
11
- (file: ts.SourceFile): ts.SourceFile => {
12
- if (file.isDeclarationFile) return file;
13
- const importer = new ImportProgrammer({
14
- internalPrefix: "nestia_core_transform",
15
- });
16
- file = ts.visitEachChild(
17
- file,
18
- (node) =>
19
- iterate_node({
20
- context: {
21
- ...context,
22
- transformer,
23
- importer,
24
- },
25
- file,
26
- node,
27
- }),
28
- transformer,
29
- );
30
- const index: number = find_import_injection_index(file);
31
- return ts.factory.updateSourceFile(
32
- file,
33
- [
34
- ...file.statements.slice(0, index),
35
- ...importer.toStatements(),
36
- ...file.statements.slice(index),
37
- ],
38
- false,
39
- file.referencedFiles,
40
- file.typeReferenceDirectives,
41
- file.hasNoDefaultLib,
42
- file.libReferenceDirectives,
43
- );
44
- };
45
-
46
- const iterate_node = (props: {
47
- context: INestiaTransformContext;
48
- file: ts.SourceFile;
49
- node: ts.Node;
50
- }): ts.Node =>
51
- ts.visitEachChild(
52
- try_transform_node(props) ?? props.node,
53
- (child) =>
54
- iterate_node({
55
- context: props.context,
56
- file: props.file,
57
- node: child,
58
- }),
59
- props.context.transformer,
60
- );
61
-
62
- const try_transform_node = (props: {
63
- context: INestiaTransformContext;
64
- file: ts.SourceFile;
65
- node: ts.Node;
66
- }): ts.Node | null => {
67
- try {
68
- return NodeTransformer.transform(props);
69
- } catch (exp) {
70
- // ONLY ACCEPT TRANSFORMER-ERROR
71
- if (!isTransformerError(exp)) throw exp;
72
-
73
- // AVOID SPECIAL BUG OF TYPESCRIPT COMPILER API
74
- (props.node as any).parent ??= props.file;
75
-
76
- // REPORT DIAGNOSTIC
77
- const diagnostic = (ts as any).createDiagnosticForNode(props.node, {
78
- key: exp.code,
79
- category: ts.DiagnosticCategory.Error,
80
- message: exp.message,
81
- code: `(${exp.code})` as any,
82
- });
83
- props.context.extras.addDiagnostic(diagnostic);
84
- return null;
85
- }
86
- };
87
-
88
- const find_import_injection_index = (file: ts.SourceFile): number => {
89
- let i: number = 0;
90
- for (; i < file.statements.length; ++i) {
91
- const stmt: ts.Statement = file.statements[i]!;
92
- if (
93
- ts.isExpressionStatement(stmt) &&
94
- ts.isStringLiteralLike(stmt.expression) &&
95
- stmt.expression.text.startsWith("use ")
96
- )
97
- continue;
98
- break;
99
- }
100
- return i;
101
- };
102
- }
103
-
104
- const isTransformerError = (error: any): error is TransformerError =>
105
- typeof error === "object" &&
106
- error !== null &&
107
- error.constructor.name === "TransformerError" &&
108
- typeof error.code === "string" &&
109
- typeof error.message === "string";
1
+ import { ImportProgrammer, TransformerError } from "@typia/core";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
5
+ import { NodeTransformer } from "./NodeTransformer";
6
+
7
+ export namespace FileTransformer {
8
+ export const transform =
9
+ (context: Omit<INestiaTransformContext, "importer" | "transformer">) =>
10
+ (transformer: ts.TransformationContext) =>
11
+ (file: ts.SourceFile): ts.SourceFile => {
12
+ if (file.isDeclarationFile) return file;
13
+ const importer = new ImportProgrammer({
14
+ internalPrefix: "nestia_core_transform",
15
+ });
16
+ file = ts.visitEachChild(
17
+ file,
18
+ (node) =>
19
+ iterate_node({
20
+ context: {
21
+ ...context,
22
+ transformer,
23
+ importer,
24
+ },
25
+ file,
26
+ node,
27
+ }),
28
+ transformer,
29
+ );
30
+ const index: number = find_import_injection_index(file);
31
+ return ts.factory.updateSourceFile(
32
+ file,
33
+ [
34
+ ...file.statements.slice(0, index),
35
+ ...importer.toStatements(),
36
+ ...file.statements.slice(index),
37
+ ],
38
+ false,
39
+ file.referencedFiles,
40
+ file.typeReferenceDirectives,
41
+ file.hasNoDefaultLib,
42
+ file.libReferenceDirectives,
43
+ );
44
+ };
45
+
46
+ const iterate_node = (props: {
47
+ context: INestiaTransformContext;
48
+ file: ts.SourceFile;
49
+ node: ts.Node;
50
+ }): ts.Node =>
51
+ ts.visitEachChild(
52
+ try_transform_node(props) ?? props.node,
53
+ (child) =>
54
+ iterate_node({
55
+ context: props.context,
56
+ file: props.file,
57
+ node: child,
58
+ }),
59
+ props.context.transformer,
60
+ );
61
+
62
+ const try_transform_node = (props: {
63
+ context: INestiaTransformContext;
64
+ file: ts.SourceFile;
65
+ node: ts.Node;
66
+ }): ts.Node | null => {
67
+ try {
68
+ return NodeTransformer.transform(props);
69
+ } catch (exp) {
70
+ // ONLY ACCEPT TRANSFORMER-ERROR
71
+ if (!isTransformerError(exp)) throw exp;
72
+
73
+ // AVOID SPECIAL BUG OF TYPESCRIPT COMPILER API
74
+ (props.node as any).parent ??= props.file;
75
+
76
+ // REPORT DIAGNOSTIC
77
+ const diagnostic = (ts as any).createDiagnosticForNode(props.node, {
78
+ key: exp.code,
79
+ category: ts.DiagnosticCategory.Error,
80
+ message: exp.message,
81
+ code: `(${exp.code})` as any,
82
+ });
83
+ props.context.extras.addDiagnostic(diagnostic);
84
+ return null;
85
+ }
86
+ };
87
+
88
+ const find_import_injection_index = (file: ts.SourceFile): number => {
89
+ let i: number = 0;
90
+ for (; i < file.statements.length; ++i) {
91
+ const stmt: ts.Statement = file.statements[i]!;
92
+ if (
93
+ ts.isExpressionStatement(stmt) &&
94
+ ts.isStringLiteralLike(stmt.expression) &&
95
+ stmt.expression.text.startsWith("use ")
96
+ )
97
+ continue;
98
+ break;
99
+ }
100
+ return i;
101
+ };
102
+ }
103
+
104
+ const isTransformerError = (error: any): error is TransformerError =>
105
+ typeof error === "object" &&
106
+ error !== null &&
107
+ error.constructor.name === "TransformerError" &&
108
+ typeof error.code === "string" &&
109
+ typeof error.message === "string";
@@ -1,103 +1,103 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
- import { TypedRouteTransformer } from "./TypedRouteTransformer";
5
- import { WebSocketRouteTransformer } from "./WebSocketRouteTransformer";
6
-
7
- export namespace MethodTransformer {
8
- export const transform = (props: {
9
- context: INestiaTransformContext;
10
- method: ts.MethodDeclaration;
11
- }): ts.MethodDeclaration => {
12
- const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
13
- ? ts.getDecorators(props.method)
14
- : (props.method as any).decorators;
15
- if (!decorators?.length) return props.method;
16
-
17
- const signature: ts.Signature | undefined =
18
- props.context.checker.getSignatureFromDeclaration(props.method);
19
- const original: ts.Type | undefined =
20
- signature && props.context.checker.getReturnTypeOfSignature(signature);
21
- const type: ts.Type | undefined =
22
- original && get_escaped_type(props.context.checker)(original);
23
-
24
- if (type === undefined) return props.method;
25
-
26
- const operator = (decorator: ts.Decorator): ts.Decorator => {
27
- decorator = TypedRouteTransformer.transform({
28
- context: props.context,
29
- decorator,
30
- type,
31
- });
32
- decorator = WebSocketRouteTransformer.validate({
33
- context: props.context,
34
- method: props.method,
35
- decorator,
36
- });
37
- return decorator;
38
- };
39
- if (ts.getDecorators !== undefined)
40
- return ts.factory.updateMethodDeclaration(
41
- props.method,
42
- (props.method.modifiers || []).map((mod) =>
43
- ts.isDecorator(mod) ? operator(mod) : mod,
44
- ),
45
- props.method.asteriskToken,
46
- props.method.name,
47
- props.method.questionToken,
48
- props.method.typeParameters,
49
- props.method.parameters,
50
- props.method.type,
51
- props.method.body,
52
- );
53
- // eslint-disable-next-line
54
- return (ts.factory.updateMethodDeclaration as any)(
55
- props.method,
56
- decorators.map(operator),
57
- (props.method as any).modifiers,
58
- props.method.asteriskToken,
59
- props.method.name,
60
- props.method.questionToken,
61
- props.method.typeParameters,
62
- props.method.parameters,
63
- props.method.type,
64
- props.method.body,
65
- );
66
- };
67
- }
68
-
69
- const get_escaped_type =
70
- (checker: ts.TypeChecker) =>
71
- (type: ts.Type): ts.Type => {
72
- const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
73
- return symbol && get_name(symbol) === "Promise"
74
- ? escape_promise(checker)(type)
75
- : type;
76
- };
77
-
78
- const escape_promise =
79
- (checker: ts.TypeChecker) =>
80
- (type: ts.Type): ts.Type => {
81
- const generic: readonly ts.Type[] = checker.getTypeArguments(
82
- type as ts.TypeReference,
83
- );
84
- if (generic.length !== 1)
85
- throw new Error(
86
- "Error on ImportAnalyzer.analyze(): invalid promise type.",
87
- );
88
- return generic[0]!;
89
- };
90
-
91
- const get_name = (symbol: ts.Symbol): string =>
92
- explore_name(symbol.getDeclarations()![0]!.parent)(
93
- symbol.escapedName.toString(),
94
- );
95
-
96
- const explore_name =
97
- (decl: ts.Node) =>
98
- (name: string): string =>
99
- ts.isModuleBlock(decl)
100
- ? explore_name(decl.parent.parent)(
101
- `${decl.parent.name.getFullText().trim()}.${name}`,
102
- )
103
- : name;
1
+ import ts from "typescript";
2
+
3
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
+ import { TypedRouteTransformer } from "./TypedRouteTransformer";
5
+ import { WebSocketRouteTransformer } from "./WebSocketRouteTransformer";
6
+
7
+ export namespace MethodTransformer {
8
+ export const transform = (props: {
9
+ context: INestiaTransformContext;
10
+ method: ts.MethodDeclaration;
11
+ }): ts.MethodDeclaration => {
12
+ const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
13
+ ? ts.getDecorators(props.method)
14
+ : (props.method as any).decorators;
15
+ if (!decorators?.length) return props.method;
16
+
17
+ const signature: ts.Signature | undefined =
18
+ props.context.checker.getSignatureFromDeclaration(props.method);
19
+ const original: ts.Type | undefined =
20
+ signature && props.context.checker.getReturnTypeOfSignature(signature);
21
+ const type: ts.Type | undefined =
22
+ original && get_escaped_type(props.context.checker)(original);
23
+
24
+ if (type === undefined) return props.method;
25
+
26
+ const operator = (decorator: ts.Decorator): ts.Decorator => {
27
+ decorator = TypedRouteTransformer.transform({
28
+ context: props.context,
29
+ decorator,
30
+ type,
31
+ });
32
+ decorator = WebSocketRouteTransformer.validate({
33
+ context: props.context,
34
+ method: props.method,
35
+ decorator,
36
+ });
37
+ return decorator;
38
+ };
39
+ if (ts.getDecorators !== undefined)
40
+ return ts.factory.updateMethodDeclaration(
41
+ props.method,
42
+ (props.method.modifiers || []).map((mod) =>
43
+ ts.isDecorator(mod) ? operator(mod) : mod,
44
+ ),
45
+ props.method.asteriskToken,
46
+ props.method.name,
47
+ props.method.questionToken,
48
+ props.method.typeParameters,
49
+ props.method.parameters,
50
+ props.method.type,
51
+ props.method.body,
52
+ );
53
+ // eslint-disable-next-line
54
+ return (ts.factory.updateMethodDeclaration as any)(
55
+ props.method,
56
+ decorators.map(operator),
57
+ (props.method as any).modifiers,
58
+ props.method.asteriskToken,
59
+ props.method.name,
60
+ props.method.questionToken,
61
+ props.method.typeParameters,
62
+ props.method.parameters,
63
+ props.method.type,
64
+ props.method.body,
65
+ );
66
+ };
67
+ }
68
+
69
+ const get_escaped_type =
70
+ (checker: ts.TypeChecker) =>
71
+ (type: ts.Type): ts.Type => {
72
+ const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
73
+ return symbol && get_name(symbol) === "Promise"
74
+ ? escape_promise(checker)(type)
75
+ : type;
76
+ };
77
+
78
+ const escape_promise =
79
+ (checker: ts.TypeChecker) =>
80
+ (type: ts.Type): ts.Type => {
81
+ const generic: readonly ts.Type[] = checker.getTypeArguments(
82
+ type as ts.TypeReference,
83
+ );
84
+ if (generic.length !== 1)
85
+ throw new Error(
86
+ "Error on ImportAnalyzer.analyze(): invalid promise type.",
87
+ );
88
+ return generic[0]!;
89
+ };
90
+
91
+ const get_name = (symbol: ts.Symbol): string =>
92
+ explore_name(symbol.getDeclarations()![0]!.parent)(
93
+ symbol.escapedName.toString(),
94
+ );
95
+
96
+ const explore_name =
97
+ (decl: ts.Node) =>
98
+ (name: string): string =>
99
+ ts.isModuleBlock(decl)
100
+ ? explore_name(decl.parent.parent)(
101
+ `${decl.parent.name.getFullText().trim()}.${name}`,
102
+ )
103
+ : name;