@nestia/core 0.1.5 → 0.1.7

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 (46) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +336 -0
  3. package/lib/decorators/PlainBody.d.ts +1 -1
  4. package/lib/decorators/PlainBody.js +1 -1
  5. package/lib/executable/core.d.ts +2 -0
  6. package/lib/executable/core.js +100 -0
  7. package/lib/executable/core.js.map +1 -0
  8. package/lib/executable/internal/CommandParser.d.ts +3 -0
  9. package/lib/executable/internal/CommandParser.js +21 -0
  10. package/lib/executable/internal/CommandParser.js.map +1 -0
  11. package/lib/executable/internal/CoreSetupWizard.d.ts +4 -0
  12. package/lib/executable/internal/CoreSetupWizard.js +259 -0
  13. package/lib/executable/internal/CoreSetupWizard.js.map +1 -0
  14. package/package.json +5 -1
  15. package/src/decorators/EncryptedBody.ts +102 -102
  16. package/src/decorators/EncryptedController.ts +43 -43
  17. package/src/decorators/EncryptedModule.ts +77 -77
  18. package/src/decorators/EncryptedRoute.ts +203 -203
  19. package/src/decorators/PlainBody.ts +38 -38
  20. package/src/decorators/TypedBody.ts +49 -49
  21. package/src/decorators/TypedParam.ts +70 -70
  22. package/src/decorators/TypedRoute.ts +149 -149
  23. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  24. package/src/decorators/internal/get_path_and_stringify.ts +77 -77
  25. package/src/decorators/internal/headers_to_object.ts +10 -10
  26. package/src/decorators/internal/route_error.ts +38 -38
  27. package/src/decorators/internal/validate_request_body.ts +59 -59
  28. package/src/executable/core.ts +46 -0
  29. package/src/executable/internal/CommandParser.ts +15 -0
  30. package/src/executable/internal/CoreSetupWizard.ts +177 -0
  31. package/src/index.ts +5 -5
  32. package/src/module.ts +11 -11
  33. package/src/options/INestiaTransformOptions.ts +6 -6
  34. package/src/options/INestiaTransformProject.ts +7 -7
  35. package/src/options/IRequestBodyValidator.ts +20 -20
  36. package/src/options/IResponseBodyStringifier.ts +25 -25
  37. package/src/transform.ts +20 -20
  38. package/src/transformers/BodyTransformer.ts +106 -106
  39. package/src/transformers/FileTransformer.ts +49 -49
  40. package/src/transformers/MethodTransformer.ts +91 -91
  41. package/src/transformers/NodeTransformer.ts +18 -18
  42. package/src/transformers/ParameterTransformer.ts +45 -45
  43. package/src/transformers/RouteTransformer.ts +131 -131
  44. package/src/typings/Creator.ts +3 -3
  45. package/src/utils/ExceptionManager.ts +126 -126
  46. package/src/utils/Singleton.ts +20 -20
@@ -1,7 +1,7 @@
1
- import { IProject } from "typia/lib/transformers/IProject";
2
-
3
- import { INestiaTransformOptions } from "./INestiaTransformOptions";
4
-
5
- export interface INestiaTransformProject extends Omit<IProject, "options"> {
6
- options: INestiaTransformOptions;
7
- }
1
+ import { IProject } from "typia/lib/transformers/IProject";
2
+
3
+ import { INestiaTransformOptions } from "./INestiaTransformOptions";
4
+
5
+ export interface INestiaTransformProject extends Omit<IProject, "options"> {
6
+ options: INestiaTransformOptions;
7
+ }
@@ -1,20 +1,20 @@
1
- import { IValidation } from "typia";
2
-
3
- export type IRequestBodyValidator<T> =
4
- | IRequestBodyValidator.IAssert<T>
5
- | IRequestBodyValidator.IIs<T>
6
- | IRequestBodyValidator.IValidate<T>;
7
- export namespace IRequestBodyValidator {
8
- export interface IAssert<T> {
9
- type: "assert";
10
- assert: (input: T) => T;
11
- }
12
- export interface IIs<T> {
13
- type: "is";
14
- is: (input: T) => boolean;
15
- }
16
- export interface IValidate<T> {
17
- type: "validate";
18
- validate: (input: T) => IValidation<T>;
19
- }
20
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export type IRequestBodyValidator<T> =
4
+ | IRequestBodyValidator.IAssert<T>
5
+ | IRequestBodyValidator.IIs<T>
6
+ | IRequestBodyValidator.IValidate<T>;
7
+ export namespace IRequestBodyValidator {
8
+ export interface IAssert<T> {
9
+ type: "assert";
10
+ assert: (input: T) => T;
11
+ }
12
+ export interface IIs<T> {
13
+ type: "is";
14
+ is: (input: T) => boolean;
15
+ }
16
+ export interface IValidate<T> {
17
+ type: "validate";
18
+ validate: (input: T) => IValidation<T>;
19
+ }
20
+ }
@@ -1,25 +1,25 @@
1
- import { IValidation } from "typia";
2
-
3
- export type IResponseBodyStringifier<T> =
4
- | IResponseBodyStringifier.IStringify<T>
5
- | IResponseBodyStringifier.IIs<T>
6
- | IResponseBodyStringifier.IAssert<T>
7
- | IResponseBodyStringifier.IValidate<T>;
8
- export namespace IResponseBodyStringifier {
9
- export interface IStringify<T> {
10
- type: "stringify";
11
- stringify: (input: T) => string;
12
- }
13
- export interface IIs<T> {
14
- type: "is";
15
- is: (input: T) => string | null;
16
- }
17
- export interface IAssert<T> {
18
- type: "assert";
19
- assert: (input: T) => string;
20
- }
21
- export interface IValidate<T> {
22
- type: "validate";
23
- validate: (input: T) => IValidation<string>;
24
- }
25
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export type IResponseBodyStringifier<T> =
4
+ | IResponseBodyStringifier.IStringify<T>
5
+ | IResponseBodyStringifier.IIs<T>
6
+ | IResponseBodyStringifier.IAssert<T>
7
+ | IResponseBodyStringifier.IValidate<T>;
8
+ export namespace IResponseBodyStringifier {
9
+ export interface IStringify<T> {
10
+ type: "stringify";
11
+ stringify: (input: T) => string;
12
+ }
13
+ export interface IIs<T> {
14
+ type: "is";
15
+ is: (input: T) => string | null;
16
+ }
17
+ export interface IAssert<T> {
18
+ type: "assert";
19
+ assert: (input: T) => string;
20
+ }
21
+ export interface IValidate<T> {
22
+ type: "validate";
23
+ validate: (input: T) => IValidation<string>;
24
+ }
25
+ }
package/src/transform.ts CHANGED
@@ -1,20 +1,20 @@
1
- import ts from "typescript";
2
- import { IProject } from "typia/lib/transformers/IProject";
3
-
4
- import { INestiaTransformOptions } from "./options/INestiaTransformOptions";
5
- import { FileTransformer } from "./transformers/FileTransformer";
6
-
7
- export default function transform(
8
- program: ts.Program,
9
- options?: INestiaTransformOptions,
10
- ): ts.TransformerFactory<ts.SourceFile> {
11
- const project: IProject = {
12
- program,
13
- compilerOptions: program.getCompilerOptions(),
14
- checker: program.getTypeChecker(),
15
- printer: ts.createPrinter(),
16
- options: options || {},
17
- };
18
- return (context) => (file) =>
19
- FileTransformer.transform(project, context, file);
20
- }
1
+ import ts from "typescript";
2
+ import { IProject } from "typia/lib/transformers/IProject";
3
+
4
+ import { INestiaTransformOptions } from "./options/INestiaTransformOptions";
5
+ import { FileTransformer } from "./transformers/FileTransformer";
6
+
7
+ export default function transform(
8
+ program: ts.Program,
9
+ options?: INestiaTransformOptions,
10
+ ): ts.TransformerFactory<ts.SourceFile> {
11
+ const project: IProject = {
12
+ program,
13
+ compilerOptions: program.getCompilerOptions(),
14
+ checker: program.getTypeChecker(),
15
+ printer: ts.createPrinter(),
16
+ options: options || {},
17
+ };
18
+ return (context) => (file) =>
19
+ FileTransformer.transform(project, context, file);
20
+ }
@@ -1,106 +1,106 @@
1
- import path from "path";
2
- import ts from "typescript";
3
- import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
4
- import { IsProgrammer } from "typia/lib/programmers/IsProgrammer";
5
- import { ValidateProgrammer } from "typia/lib/programmers/ValidateProgrammer";
6
- import { IProject } from "typia/lib/transformers/IProject";
7
-
8
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
9
-
10
- export namespace BodyTransformer {
11
- export function transform(
12
- project: INestiaTransformProject,
13
- type: ts.Type,
14
- decorator: ts.Decorator,
15
- ): ts.Decorator {
16
- if (!ts.isCallExpression(decorator.expression)) return decorator;
17
- return ts.factory.createDecorator(
18
- validate(project, type, decorator.expression),
19
- );
20
- }
21
-
22
- function validate(
23
- project: INestiaTransformProject,
24
- type: ts.Type,
25
- expression: ts.CallExpression,
26
- ): ts.LeftHandSideExpression {
27
- // CHECK SIGNATURE
28
- const signature: ts.Signature | undefined =
29
- project.checker.getResolvedSignature(expression);
30
- if (!signature || !signature.declaration) return expression;
31
-
32
- // CHECK TO BE TRANSFORMED
33
- const validate: boolean = (() => {
34
- // CHECK FILENAME
35
- const location: string = path.resolve(
36
- signature.declaration.getSourceFile().fileName,
37
- );
38
- if (
39
- LIB_PATHS.every((str) => location.indexOf(str) === -1) &&
40
- SRC_PATHS.every((str) => location !== str)
41
- )
42
- return false;
43
-
44
- // CHECK DUPLICATED TRANSFORMATION
45
- return expression.arguments.length === 0;
46
- })();
47
- if (validate === false) return expression;
48
-
49
- // CHECK TYPE NODE
50
- const typeNode: ts.TypeNode | undefined =
51
- project.checker.typeToTypeNode(type, undefined, undefined);
52
- if (typeNode === undefined) return expression;
53
-
54
- //----
55
- // TRANSFORMATION
56
- //----
57
- // GENERATE VALIDATION PLAN
58
- const parameter = (
59
- key: string,
60
- programmer: (
61
- project: IProject,
62
- modulo: ts.LeftHandSideExpression,
63
- ) => (type: ts.Type) => ts.ArrowFunction,
64
- ) =>
65
- ts.factory.createObjectLiteralExpression([
66
- ts.factory.createPropertyAssignment(
67
- ts.factory.createIdentifier("type"),
68
- ts.factory.createStringLiteral(key),
69
- ),
70
- ts.factory.createPropertyAssignment(
71
- ts.factory.createIdentifier(key),
72
- programmer(project, expression.expression)(type),
73
- ),
74
- ]);
75
- const validator: ts.ObjectLiteralExpression = (() => {
76
- if (project.options.validate === "is")
77
- return parameter("is", IsProgrammer.generate);
78
- else if (project.options.validate === "validate")
79
- return parameter("validate", ValidateProgrammer.generate);
80
- return parameter("assert", AssertProgrammer.generate);
81
- })();
82
-
83
- // UPDATE DECORATOR FUNCTION CALL
84
- return ts.factory.updateCallExpression(
85
- expression,
86
- expression.expression,
87
- expression.typeArguments,
88
- [validator],
89
- );
90
- }
91
-
92
- const CLASSES = ["EncryptedBody", "TypedBody"];
93
- const LIB_PATHS = CLASSES.map((cla) =>
94
- path.join(
95
- "node_modules",
96
- "@nestia",
97
- "core",
98
- "lib",
99
- "decorators",
100
- `${cla}.d.ts`,
101
- ),
102
- );
103
- const SRC_PATHS = CLASSES.map((cla) =>
104
- path.resolve(path.join(__dirname, "..", "decorators", `${cla}.ts`)),
105
- );
106
- }
1
+ import path from "path";
2
+ import ts from "typescript";
3
+ import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
4
+ import { IsProgrammer } from "typia/lib/programmers/IsProgrammer";
5
+ import { ValidateProgrammer } from "typia/lib/programmers/ValidateProgrammer";
6
+ import { IProject } from "typia/lib/transformers/IProject";
7
+
8
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
9
+
10
+ export namespace BodyTransformer {
11
+ export function transform(
12
+ project: INestiaTransformProject,
13
+ type: ts.Type,
14
+ decorator: ts.Decorator,
15
+ ): ts.Decorator {
16
+ if (!ts.isCallExpression(decorator.expression)) return decorator;
17
+ return ts.factory.createDecorator(
18
+ validate(project, type, decorator.expression),
19
+ );
20
+ }
21
+
22
+ function validate(
23
+ project: INestiaTransformProject,
24
+ type: ts.Type,
25
+ expression: ts.CallExpression,
26
+ ): ts.LeftHandSideExpression {
27
+ // CHECK SIGNATURE
28
+ const signature: ts.Signature | undefined =
29
+ project.checker.getResolvedSignature(expression);
30
+ if (!signature || !signature.declaration) return expression;
31
+
32
+ // CHECK TO BE TRANSFORMED
33
+ const validate: boolean = (() => {
34
+ // CHECK FILENAME
35
+ const location: string = path.resolve(
36
+ signature.declaration.getSourceFile().fileName,
37
+ );
38
+ if (
39
+ LIB_PATHS.every((str) => location.indexOf(str) === -1) &&
40
+ SRC_PATHS.every((str) => location !== str)
41
+ )
42
+ return false;
43
+
44
+ // CHECK DUPLICATED TRANSFORMATION
45
+ return expression.arguments.length === 0;
46
+ })();
47
+ if (validate === false) return expression;
48
+
49
+ // CHECK TYPE NODE
50
+ const typeNode: ts.TypeNode | undefined =
51
+ project.checker.typeToTypeNode(type, undefined, undefined);
52
+ if (typeNode === undefined) return expression;
53
+
54
+ //----
55
+ // TRANSFORMATION
56
+ //----
57
+ // GENERATE VALIDATION PLAN
58
+ const parameter = (
59
+ key: string,
60
+ programmer: (
61
+ project: IProject,
62
+ modulo: ts.LeftHandSideExpression,
63
+ ) => (type: ts.Type) => ts.ArrowFunction,
64
+ ) =>
65
+ ts.factory.createObjectLiteralExpression([
66
+ ts.factory.createPropertyAssignment(
67
+ ts.factory.createIdentifier("type"),
68
+ ts.factory.createStringLiteral(key),
69
+ ),
70
+ ts.factory.createPropertyAssignment(
71
+ ts.factory.createIdentifier(key),
72
+ programmer(project, expression.expression)(type),
73
+ ),
74
+ ]);
75
+ const validator: ts.ObjectLiteralExpression = (() => {
76
+ if (project.options.validate === "is")
77
+ return parameter("is", IsProgrammer.generate);
78
+ else if (project.options.validate === "validate")
79
+ return parameter("validate", ValidateProgrammer.generate);
80
+ return parameter("assert", AssertProgrammer.generate);
81
+ })();
82
+
83
+ // UPDATE DECORATOR FUNCTION CALL
84
+ return ts.factory.updateCallExpression(
85
+ expression,
86
+ expression.expression,
87
+ expression.typeArguments,
88
+ [validator],
89
+ );
90
+ }
91
+
92
+ const CLASSES = ["EncryptedBody", "TypedBody"];
93
+ const LIB_PATHS = CLASSES.map((cla) =>
94
+ path.join(
95
+ "node_modules",
96
+ "@nestia",
97
+ "core",
98
+ "lib",
99
+ "decorators",
100
+ `${cla}.d.ts`,
101
+ ),
102
+ );
103
+ const SRC_PATHS = CLASSES.map((cla) =>
104
+ path.resolve(path.join(__dirname, "..", "decorators", `${cla}.ts`)),
105
+ );
106
+ }
@@ -1,49 +1,49 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
4
- import { NodeTransformer } from "./NodeTransformer";
5
-
6
- export namespace FileTransformer {
7
- export function transform(
8
- project: INestiaTransformProject,
9
- context: ts.TransformationContext,
10
- file: ts.SourceFile,
11
- ): ts.SourceFile {
12
- // ITERATE NODES
13
- return ts.visitEachChild(
14
- file,
15
- (node) => iterate_node(project, context, node),
16
- context,
17
- );
18
- }
19
-
20
- function iterate_node(
21
- project: INestiaTransformProject,
22
- context: ts.TransformationContext,
23
- node: ts.Node,
24
- ): ts.Node {
25
- return ts.visitEachChild(
26
- try_transform_node(project, node),
27
- (child) => iterate_node(project, context, child),
28
- context,
29
- );
30
- }
31
-
32
- function try_transform_node(
33
- project: INestiaTransformProject,
34
- node: ts.Node,
35
- ): ts.Node {
36
- try {
37
- return NodeTransformer.transform(project, node);
38
- } catch (exp) {
39
- if (!(exp instanceof Error)) throw exp;
40
-
41
- const file: ts.SourceFile = node.getSourceFile();
42
- const { line, character } = file.getLineAndCharacterOfPosition(
43
- node.pos,
44
- );
45
- exp.message += ` - ${file.fileName}.${line + 1}:${character + 1}`;
46
- throw exp;
47
- }
48
- }
49
- }
1
+ import ts from "typescript";
2
+
3
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
4
+ import { NodeTransformer } from "./NodeTransformer";
5
+
6
+ export namespace FileTransformer {
7
+ export function transform(
8
+ project: INestiaTransformProject,
9
+ context: ts.TransformationContext,
10
+ file: ts.SourceFile,
11
+ ): ts.SourceFile {
12
+ // ITERATE NODES
13
+ return ts.visitEachChild(
14
+ file,
15
+ (node) => iterate_node(project, context, node),
16
+ context,
17
+ );
18
+ }
19
+
20
+ function iterate_node(
21
+ project: INestiaTransformProject,
22
+ context: ts.TransformationContext,
23
+ node: ts.Node,
24
+ ): ts.Node {
25
+ return ts.visitEachChild(
26
+ try_transform_node(project, node),
27
+ (child) => iterate_node(project, context, child),
28
+ context,
29
+ );
30
+ }
31
+
32
+ function try_transform_node(
33
+ project: INestiaTransformProject,
34
+ node: ts.Node,
35
+ ): ts.Node {
36
+ try {
37
+ return NodeTransformer.transform(project, node);
38
+ } catch (exp) {
39
+ if (!(exp instanceof Error)) throw exp;
40
+
41
+ const file: ts.SourceFile = node.getSourceFile();
42
+ const { line, character } = file.getLineAndCharacterOfPosition(
43
+ node.pos,
44
+ );
45
+ exp.message += ` - ${file.fileName}.${line + 1}:${character + 1}`;
46
+ throw exp;
47
+ }
48
+ }
49
+ }
@@ -1,91 +1,91 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
4
- import { RouteTransformer } from "./RouteTransformer";
5
-
6
- export namespace MethodTransformer {
7
- export function transform(
8
- project: INestiaTransformProject,
9
- method: ts.MethodDeclaration,
10
- ): ts.MethodDeclaration {
11
- const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
12
- ? ts.getDecorators(method)
13
- : (method as any).decorators;
14
- if (!decorators?.length) return method;
15
-
16
- const signature: ts.Signature | undefined =
17
- project.checker.getSignatureFromDeclaration(method);
18
- const original: ts.Type | undefined =
19
- signature && project.checker.getReturnTypeOfSignature(signature);
20
- const escaped: ts.Type | undefined =
21
- original && get_escaped_type(project.checker, original);
22
-
23
- if (escaped === undefined) return method;
24
-
25
- if (ts.getDecorators !== undefined)
26
- return ts.factory.updateMethodDeclaration(
27
- method,
28
- (method.modifiers || []).map((mod) =>
29
- ts.isDecorator(mod)
30
- ? RouteTransformer.transform(project, escaped, mod)
31
- : mod,
32
- ),
33
- method.asteriskToken,
34
- method.name,
35
- method.questionToken,
36
- method.typeParameters,
37
- method.parameters,
38
- method.type,
39
- method.body,
40
- );
41
- // eslint-disable-next-line
42
- return ts.factory.updateMethodDeclaration(
43
- method,
44
- decorators.map((deco) =>
45
- RouteTransformer.transform(project, escaped, deco),
46
- ),
47
- (method as any).modifiers,
48
- method.asteriskToken,
49
- method.name,
50
- method.questionToken,
51
- method.typeParameters,
52
- method.parameters,
53
- method.type,
54
- method.body,
55
- );
56
- }
57
- }
58
-
59
- function get_escaped_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
60
- const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
61
- return symbol && get_name(symbol) === "Promise"
62
- ? escape_promise(checker, type)
63
- : type;
64
- }
65
-
66
- function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
67
- const generic: readonly ts.Type[] = checker.getTypeArguments(
68
- type as ts.TypeReference,
69
- );
70
- if (generic.length !== 1)
71
- throw new Error(
72
- "Error on ImportAnalyzer.analyze(): invalid promise type.",
73
- );
74
- return generic[0];
75
- }
76
-
77
- function get_name(symbol: ts.Symbol): string {
78
- return explore_name(
79
- symbol.escapedName.toString(),
80
- symbol.getDeclarations()![0].parent,
81
- );
82
- }
83
-
84
- function explore_name(name: string, decl: ts.Node): string {
85
- return ts.isModuleBlock(decl)
86
- ? explore_name(
87
- `${decl.parent.name.getText()}.${name}`,
88
- decl.parent.parent,
89
- )
90
- : name;
91
- }
1
+ import ts from "typescript";
2
+
3
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
4
+ import { RouteTransformer } from "./RouteTransformer";
5
+
6
+ export namespace MethodTransformer {
7
+ export function transform(
8
+ project: INestiaTransformProject,
9
+ method: ts.MethodDeclaration,
10
+ ): ts.MethodDeclaration {
11
+ const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
12
+ ? ts.getDecorators(method)
13
+ : (method as any).decorators;
14
+ if (!decorators?.length) return method;
15
+
16
+ const signature: ts.Signature | undefined =
17
+ project.checker.getSignatureFromDeclaration(method);
18
+ const original: ts.Type | undefined =
19
+ signature && project.checker.getReturnTypeOfSignature(signature);
20
+ const escaped: ts.Type | undefined =
21
+ original && get_escaped_type(project.checker, original);
22
+
23
+ if (escaped === undefined) return method;
24
+
25
+ if (ts.getDecorators !== undefined)
26
+ return ts.factory.updateMethodDeclaration(
27
+ method,
28
+ (method.modifiers || []).map((mod) =>
29
+ ts.isDecorator(mod)
30
+ ? RouteTransformer.transform(project, escaped, mod)
31
+ : mod,
32
+ ),
33
+ method.asteriskToken,
34
+ method.name,
35
+ method.questionToken,
36
+ method.typeParameters,
37
+ method.parameters,
38
+ method.type,
39
+ method.body,
40
+ );
41
+ // eslint-disable-next-line
42
+ return ts.factory.updateMethodDeclaration(
43
+ method,
44
+ decorators.map((deco) =>
45
+ RouteTransformer.transform(project, escaped, deco),
46
+ ),
47
+ (method as any).modifiers,
48
+ method.asteriskToken,
49
+ method.name,
50
+ method.questionToken,
51
+ method.typeParameters,
52
+ method.parameters,
53
+ method.type,
54
+ method.body,
55
+ );
56
+ }
57
+ }
58
+
59
+ function get_escaped_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
60
+ const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
61
+ return symbol && get_name(symbol) === "Promise"
62
+ ? escape_promise(checker, type)
63
+ : type;
64
+ }
65
+
66
+ function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
67
+ const generic: readonly ts.Type[] = checker.getTypeArguments(
68
+ type as ts.TypeReference,
69
+ );
70
+ if (generic.length !== 1)
71
+ throw new Error(
72
+ "Error on ImportAnalyzer.analyze(): invalid promise type.",
73
+ );
74
+ return generic[0];
75
+ }
76
+
77
+ function get_name(symbol: ts.Symbol): string {
78
+ return explore_name(
79
+ symbol.escapedName.toString(),
80
+ symbol.getDeclarations()![0].parent,
81
+ );
82
+ }
83
+
84
+ function explore_name(name: string, decl: ts.Node): string {
85
+ return ts.isModuleBlock(decl)
86
+ ? explore_name(
87
+ `${decl.parent.name.getText()}.${name}`,
88
+ decl.parent.parent,
89
+ )
90
+ : name;
91
+ }