@nestia/core 4.4.1 → 4.4.2-dev.20241217

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 (88) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +87 -87
  3. package/lib/programmers/TypedBodyProgrammer.js +1 -2
  4. package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
  5. package/lib/programmers/TypedQueryBodyProgrammer.js +6 -6
  6. package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -1
  7. package/lib/programmers/TypedQueryProgrammer.js +5 -5
  8. package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
  9. package/lib/programmers/TypedQueryRouteProgrammer.js +5 -5
  10. package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -1
  11. package/lib/programmers/TypedRouteProgrammer.js +1 -2
  12. package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
  13. package/package.json +3 -3
  14. package/src/adaptors/WebSocketAdaptor.ts +426 -426
  15. package/src/decorators/DynamicModule.ts +43 -43
  16. package/src/decorators/EncryptedBody.ts +101 -101
  17. package/src/decorators/EncryptedController.ts +38 -38
  18. package/src/decorators/EncryptedModule.ts +100 -100
  19. package/src/decorators/EncryptedRoute.ts +219 -219
  20. package/src/decorators/NoTransformConfigurationError.ts +32 -32
  21. package/src/decorators/PlainBody.ts +79 -79
  22. package/src/decorators/SwaggerCustomizer.ts +115 -115
  23. package/src/decorators/SwaggerExample.ts +100 -100
  24. package/src/decorators/TypedBody.ts +59 -59
  25. package/src/decorators/TypedException.ts +128 -128
  26. package/src/decorators/TypedFormData.ts +195 -195
  27. package/src/decorators/TypedHeaders.ts +64 -64
  28. package/src/decorators/TypedParam.ts +77 -77
  29. package/src/decorators/TypedQuery.ts +245 -245
  30. package/src/decorators/TypedRoute.ts +214 -214
  31. package/src/decorators/WebSocketRoute.ts +242 -242
  32. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  33. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  34. package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
  35. package/src/decorators/internal/get_path_and_querify.ts +108 -108
  36. package/src/decorators/internal/get_path_and_stringify.ts +122 -122
  37. package/src/decorators/internal/get_text_body.ts +20 -20
  38. package/src/decorators/internal/headers_to_object.ts +13 -13
  39. package/src/decorators/internal/is_request_body_undefined.ts +14 -14
  40. package/src/decorators/internal/load_controller.ts +49 -49
  41. package/src/decorators/internal/route_error.ts +45 -45
  42. package/src/decorators/internal/validate_request_body.ts +74 -74
  43. package/src/decorators/internal/validate_request_form_data.ts +77 -77
  44. package/src/decorators/internal/validate_request_headers.ts +86 -86
  45. package/src/decorators/internal/validate_request_query.ts +74 -74
  46. package/src/index.ts +5 -5
  47. package/src/module.ts +21 -21
  48. package/src/options/INestiaTransformOptions.ts +38 -38
  49. package/src/options/INestiaTransformProject.ts +8 -8
  50. package/src/options/IRequestBodyValidator.ts +20 -20
  51. package/src/options/IRequestFormDataProps.ts +27 -27
  52. package/src/options/IRequestHeadersValidator.ts +22 -22
  53. package/src/options/IRequestQueryValidator.ts +20 -20
  54. package/src/options/IResponseBodyQuerifier.ts +25 -25
  55. package/src/options/IResponseBodyStringifier.ts +30 -30
  56. package/src/programmers/PlainBodyProgrammer.ts +70 -70
  57. package/src/programmers/TypedBodyProgrammer.ts +142 -143
  58. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  59. package/src/programmers/TypedHeadersProgrammer.ts +63 -63
  60. package/src/programmers/TypedParamProgrammer.ts +33 -33
  61. package/src/programmers/TypedQueryBodyProgrammer.ts +112 -106
  62. package/src/programmers/TypedQueryProgrammer.ts +114 -108
  63. package/src/programmers/TypedQueryRouteProgrammer.ts +105 -99
  64. package/src/programmers/TypedRouteProgrammer.ts +94 -95
  65. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +72 -72
  66. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +75 -75
  67. package/src/programmers/http/HttpQuerifyProgrammer.ts +108 -108
  68. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +76 -76
  69. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  70. package/src/transform.ts +35 -35
  71. package/src/transformers/FileTransformer.ts +110 -110
  72. package/src/transformers/MethodTransformer.ts +103 -103
  73. package/src/transformers/NodeTransformer.ts +23 -23
  74. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  75. package/src/transformers/ParameterTransformer.ts +57 -57
  76. package/src/transformers/TypedRouteTransformer.ts +85 -85
  77. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
  78. package/src/typings/Creator.ts +3 -3
  79. package/src/typings/get-function-location.d.ts +7 -7
  80. package/src/utils/ArrayUtil.ts +7 -7
  81. package/src/utils/ExceptionManager.ts +112 -112
  82. package/src/utils/Singleton.ts +20 -20
  83. package/src/utils/SourceFinder.ts +57 -57
  84. package/src/utils/VersioningStrategy.ts +27 -27
  85. package/lib/programmers/internal/LlmValidatePredicator.d.ts +0 -5
  86. package/lib/programmers/internal/LlmValidatePredicator.js +0 -18
  87. package/lib/programmers/internal/LlmValidatePredicator.js.map +0 -1
  88. package/src/programmers/internal/LlmValidatePredicator.ts +0 -16
@@ -1,21 +1,21 @@
1
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
2
-
3
- export namespace CoreMetadataUtil {
4
- export const atomics = (
5
- meta: Metadata,
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: Metadata): 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 { Metadata } from "typia/lib/schemas/metadata/Metadata";
2
+
3
+ export namespace CoreMetadataUtil {
4
+ export const atomics = (
5
+ meta: Metadata,
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: Metadata): 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 ts from "typescript";
2
- import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
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 ts from "typescript";
2
+ import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
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,110 +1,110 @@
1
- import ts from "typescript";
2
- import { ImportProgrammer } from "typia/lib/programmers/ImportProgrammer";
3
- import { TransformerError } from "typia/lib/transformers/TransformerError";
4
-
5
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
6
- import { NodeTransformer } from "./NodeTransformer";
7
-
8
- export namespace FileTransformer {
9
- export const transform =
10
- (context: Omit<INestiaTransformContext, "importer" | "transformer">) =>
11
- (transformer: ts.TransformationContext) =>
12
- (file: ts.SourceFile): ts.SourceFile => {
13
- if (file.isDeclarationFile) return file;
14
- const importer = new ImportProgrammer({
15
- internalPrefix: "nestia_core_transform",
16
- });
17
- file = ts.visitEachChild(
18
- file,
19
- (node) =>
20
- iterate_node({
21
- context: {
22
- ...context,
23
- transformer,
24
- importer,
25
- },
26
- file,
27
- node,
28
- }),
29
- transformer,
30
- );
31
- const index: number = find_import_injection_index(file);
32
- return ts.factory.updateSourceFile(
33
- file,
34
- [
35
- ...file.statements.slice(0, index),
36
- ...importer.toStatements(),
37
- ...file.statements.slice(index),
38
- ],
39
- false,
40
- file.referencedFiles,
41
- file.typeReferenceDirectives,
42
- file.hasNoDefaultLib,
43
- file.libReferenceDirectives,
44
- );
45
- };
46
-
47
- const iterate_node = (props: {
48
- context: INestiaTransformContext;
49
- file: ts.SourceFile;
50
- node: ts.Node;
51
- }): ts.Node =>
52
- ts.visitEachChild(
53
- try_transform_node(props) ?? props.node,
54
- (child) =>
55
- iterate_node({
56
- context: props.context,
57
- file: props.file,
58
- node: child,
59
- }),
60
- props.context.transformer,
61
- );
62
-
63
- const try_transform_node = (props: {
64
- context: INestiaTransformContext;
65
- file: ts.SourceFile;
66
- node: ts.Node;
67
- }): ts.Node | null => {
68
- try {
69
- return NodeTransformer.transform(props);
70
- } catch (exp) {
71
- // ONLY ACCEPT TRANSFORMER-ERROR
72
- if (!isTransformerError(exp)) throw exp;
73
-
74
- // AVOID SPECIAL BUG OF TYPESCRIPT COMPILER API
75
- (props.node as any).parent ??= props.file;
76
-
77
- // REPORT DIAGNOSTIC
78
- const diagnostic = (ts as any).createDiagnosticForNode(props.node, {
79
- key: exp.code,
80
- category: ts.DiagnosticCategory.Error,
81
- message: exp.message,
82
- code: `(${exp.code})` as any,
83
- });
84
- props.context.extras.addDiagnostic(diagnostic);
85
- return null;
86
- }
87
- };
88
-
89
- const find_import_injection_index = (file: ts.SourceFile): number => {
90
- let i: number = 0;
91
- for (; i < file.statements.length; ++i) {
92
- const stmt: ts.Statement = file.statements[i]!;
93
- if (
94
- ts.isExpressionStatement(stmt) &&
95
- ts.isStringLiteralLike(stmt.expression) &&
96
- stmt.expression.text.startsWith("use ")
97
- )
98
- continue;
99
- break;
100
- }
101
- return i;
102
- };
103
- }
104
-
105
- const isTransformerError = (error: any): error is TransformerError =>
106
- typeof error === "object" &&
107
- error !== null &&
108
- error.constructor.name === "TransformerError" &&
109
- typeof error.code === "string" &&
110
- typeof error.message === "string";
1
+ import ts from "typescript";
2
+ import { ImportProgrammer } from "typia/lib/programmers/ImportProgrammer";
3
+ import { TransformerError } from "typia/lib/transformers/TransformerError";
4
+
5
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
6
+ import { NodeTransformer } from "./NodeTransformer";
7
+
8
+ export namespace FileTransformer {
9
+ export const transform =
10
+ (context: Omit<INestiaTransformContext, "importer" | "transformer">) =>
11
+ (transformer: ts.TransformationContext) =>
12
+ (file: ts.SourceFile): ts.SourceFile => {
13
+ if (file.isDeclarationFile) return file;
14
+ const importer = new ImportProgrammer({
15
+ internalPrefix: "nestia_core_transform",
16
+ });
17
+ file = ts.visitEachChild(
18
+ file,
19
+ (node) =>
20
+ iterate_node({
21
+ context: {
22
+ ...context,
23
+ transformer,
24
+ importer,
25
+ },
26
+ file,
27
+ node,
28
+ }),
29
+ transformer,
30
+ );
31
+ const index: number = find_import_injection_index(file);
32
+ return ts.factory.updateSourceFile(
33
+ file,
34
+ [
35
+ ...file.statements.slice(0, index),
36
+ ...importer.toStatements(),
37
+ ...file.statements.slice(index),
38
+ ],
39
+ false,
40
+ file.referencedFiles,
41
+ file.typeReferenceDirectives,
42
+ file.hasNoDefaultLib,
43
+ file.libReferenceDirectives,
44
+ );
45
+ };
46
+
47
+ const iterate_node = (props: {
48
+ context: INestiaTransformContext;
49
+ file: ts.SourceFile;
50
+ node: ts.Node;
51
+ }): ts.Node =>
52
+ ts.visitEachChild(
53
+ try_transform_node(props) ?? props.node,
54
+ (child) =>
55
+ iterate_node({
56
+ context: props.context,
57
+ file: props.file,
58
+ node: child,
59
+ }),
60
+ props.context.transformer,
61
+ );
62
+
63
+ const try_transform_node = (props: {
64
+ context: INestiaTransformContext;
65
+ file: ts.SourceFile;
66
+ node: ts.Node;
67
+ }): ts.Node | null => {
68
+ try {
69
+ return NodeTransformer.transform(props);
70
+ } catch (exp) {
71
+ // ONLY ACCEPT TRANSFORMER-ERROR
72
+ if (!isTransformerError(exp)) throw exp;
73
+
74
+ // AVOID SPECIAL BUG OF TYPESCRIPT COMPILER API
75
+ (props.node as any).parent ??= props.file;
76
+
77
+ // REPORT DIAGNOSTIC
78
+ const diagnostic = (ts as any).createDiagnosticForNode(props.node, {
79
+ key: exp.code,
80
+ category: ts.DiagnosticCategory.Error,
81
+ message: exp.message,
82
+ code: `(${exp.code})` as any,
83
+ });
84
+ props.context.extras.addDiagnostic(diagnostic);
85
+ return null;
86
+ }
87
+ };
88
+
89
+ const find_import_injection_index = (file: ts.SourceFile): number => {
90
+ let i: number = 0;
91
+ for (; i < file.statements.length; ++i) {
92
+ const stmt: ts.Statement = file.statements[i]!;
93
+ if (
94
+ ts.isExpressionStatement(stmt) &&
95
+ ts.isStringLiteralLike(stmt.expression) &&
96
+ stmt.expression.text.startsWith("use ")
97
+ )
98
+ continue;
99
+ break;
100
+ }
101
+ return i;
102
+ };
103
+ }
104
+
105
+ const isTransformerError = (error: any): error is TransformerError =>
106
+ typeof error === "object" &&
107
+ error !== null &&
108
+ error.constructor.name === "TransformerError" &&
109
+ typeof error.code === "string" &&
110
+ 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;
@@ -1,23 +1,23 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
- import { MethodTransformer } from "./MethodTransformer";
5
- import { ParameterTransformer } from "./ParameterTransformer";
6
-
7
- export namespace NodeTransformer {
8
- export const transform = (props: {
9
- context: INestiaTransformContext;
10
- node: ts.Node;
11
- }): ts.Node =>
12
- ts.isMethodDeclaration(props.node)
13
- ? MethodTransformer.transform({
14
- context: props.context,
15
- method: props.node,
16
- })
17
- : ts.isParameter(props.node)
18
- ? ParameterTransformer.transform({
19
- context: props.context,
20
- param: props.node,
21
- })
22
- : props.node;
23
- }
1
+ import ts from "typescript";
2
+
3
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
+ import { MethodTransformer } from "./MethodTransformer";
5
+ import { ParameterTransformer } from "./ParameterTransformer";
6
+
7
+ export namespace NodeTransformer {
8
+ export const transform = (props: {
9
+ context: INestiaTransformContext;
10
+ node: ts.Node;
11
+ }): ts.Node =>
12
+ ts.isMethodDeclaration(props.node)
13
+ ? MethodTransformer.transform({
14
+ context: props.context,
15
+ method: props.node,
16
+ })
17
+ : ts.isParameter(props.node)
18
+ ? ParameterTransformer.transform({
19
+ context: props.context,
20
+ param: props.node,
21
+ })
22
+ : props.node;
23
+ }