@nestia/sdk 2.6.3 → 2.6.4-dev.20240401
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.
- package/lib/INestiaConfig.d.ts +14 -2
- package/lib/executable/internal/NestiaConfigLoader.js +31 -5
- package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
- package/lib/generates/SwaggerGenerator.d.ts +2 -0
- package/lib/generates/SwaggerGenerator.js +19 -3
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/structures/ISwagger.d.ts +5 -28
- package/lib/structures/ISwaggerServer.d.ts +15 -0
- package/lib/structures/ISwaggerServer.js +3 -0
- package/lib/structures/ISwaggerServer.js.map +1 -0
- package/lib/structures/ISwaggerTag.d.ts +9 -0
- package/lib/structures/ISwaggerTag.js +3 -0
- package/lib/structures/ISwaggerTag.js.map +1 -0
- package/package.json +3 -3
- package/src/INestiaConfig.ts +15 -2
- package/src/analyses/ControllerAnalyzer.ts +402 -402
- package/src/analyses/ImportAnalyzer.ts +137 -137
- package/src/analyses/ReflectAnalyzer.ts +463 -463
- package/src/generates/SwaggerGenerator.ts +466 -446
- package/src/generates/internal/ImportDictionary.ts +147 -147
- package/src/structures/ISwagger.ts +8 -33
- package/src/structures/ISwaggerServer.ts +16 -0
- package/src/structures/ISwaggerTag.ts +9 -0
- package/src/structures/TypeEntry.ts +22 -22
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
import { HashMap, HashSet } from "tstl";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { ITypeTuple } from "../structures/ITypeTuple";
|
|
5
|
-
import { GenericAnalyzer } from "./GenericAnalyzer";
|
|
6
|
-
|
|
7
|
-
export namespace ImportAnalyzer {
|
|
8
|
-
export interface IOutput {
|
|
9
|
-
features: [string, string[]][];
|
|
10
|
-
alias: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type Dictionary = HashMap<string, HashSet<string>>;
|
|
14
|
-
|
|
15
|
-
export function analyze(
|
|
16
|
-
checker: ts.TypeChecker,
|
|
17
|
-
genericDict: GenericAnalyzer.Dictionary,
|
|
18
|
-
importDict: Dictionary,
|
|
19
|
-
type: ts.Type,
|
|
20
|
-
): ITypeTuple | null {
|
|
21
|
-
type = get_type(checker, type);
|
|
22
|
-
explore_escaped_name(checker, genericDict, importDict, type);
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
return {
|
|
26
|
-
type,
|
|
27
|
-
typeName: explore_escaped_name(checker, genericDict, importDict, type),
|
|
28
|
-
};
|
|
29
|
-
} catch {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/* ---------------------------------------------------------
|
|
35
|
-
TYPE
|
|
36
|
-
--------------------------------------------------------- */
|
|
37
|
-
function get_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
|
|
38
|
-
const symbol: ts.Symbol | undefined = type.getSymbol();
|
|
39
|
-
return symbol && get_name(symbol) === "Promise"
|
|
40
|
-
? escape_promise(checker, type)
|
|
41
|
-
: type;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
|
|
45
|
-
const generic: readonly ts.Type[] = checker.getTypeArguments(
|
|
46
|
-
type as ts.TypeReference,
|
|
47
|
-
);
|
|
48
|
-
if (generic.length !== 1)
|
|
49
|
-
throw new Error(
|
|
50
|
-
"Error on ImportAnalyzer.analyze(): invalid promise type.",
|
|
51
|
-
);
|
|
52
|
-
return generic[0];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function get_name(symbol: ts.Symbol): string {
|
|
56
|
-
return explore_name(
|
|
57
|
-
symbol.escapedName.toString(),
|
|
58
|
-
symbol.getDeclarations()?.[0]?.parent,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/* ---------------------------------------------------------
|
|
63
|
-
ESCAPED TEXT WITH IMPORT STATEMENTS
|
|
64
|
-
--------------------------------------------------------- */
|
|
65
|
-
function explore_escaped_name(
|
|
66
|
-
checker: ts.TypeChecker,
|
|
67
|
-
genericDict: GenericAnalyzer.Dictionary,
|
|
68
|
-
importDict: Dictionary,
|
|
69
|
-
type: ts.Type,
|
|
70
|
-
): string {
|
|
71
|
-
//----
|
|
72
|
-
// CONDITIONAL BRANCHES
|
|
73
|
-
//----
|
|
74
|
-
// DECOMPOSE GENERIC ARGUMENT
|
|
75
|
-
while (genericDict.has(type) === true) type = genericDict.get(type)!;
|
|
76
|
-
|
|
77
|
-
// PRIMITIVE
|
|
78
|
-
const symbol: ts.Symbol | undefined = type.aliasSymbol ?? type.getSymbol();
|
|
79
|
-
|
|
80
|
-
// UNION OR INTERSECT
|
|
81
|
-
if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
|
|
82
|
-
const joiner: string = type.isIntersection() ? " & " : " | ";
|
|
83
|
-
return type.types
|
|
84
|
-
.map((child) =>
|
|
85
|
-
explore_escaped_name(checker, genericDict, importDict, child),
|
|
86
|
-
)
|
|
87
|
-
.join(joiner);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// NO SYMBOL
|
|
91
|
-
else if (symbol === undefined)
|
|
92
|
-
return checker.typeToString(
|
|
93
|
-
type,
|
|
94
|
-
undefined,
|
|
95
|
-
ts.TypeFormatFlags.NoTruncation,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
//----
|
|
99
|
-
// SPECIALIZATION
|
|
100
|
-
//----
|
|
101
|
-
const name: string = get_name(symbol);
|
|
102
|
-
const sourceFile: ts.SourceFile | undefined =
|
|
103
|
-
symbol.declarations?.[0]?.getSourceFile();
|
|
104
|
-
if (sourceFile === undefined) return name;
|
|
105
|
-
|
|
106
|
-
if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
|
|
107
|
-
const set: HashSet<string> = importDict.take(
|
|
108
|
-
sourceFile.fileName,
|
|
109
|
-
() => new HashSet(),
|
|
110
|
-
);
|
|
111
|
-
set.insert(name.split(".")[0]);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// CHECK GENERIC
|
|
115
|
-
const generic: readonly ts.Type[] = type.aliasSymbol
|
|
116
|
-
? type.aliasTypeArguments || []
|
|
117
|
-
: checker.getTypeArguments(type as ts.TypeReference);
|
|
118
|
-
return generic.length
|
|
119
|
-
? name === "Promise"
|
|
120
|
-
? explore_escaped_name(checker, genericDict, importDict, generic[0])
|
|
121
|
-
: `${name}<${generic
|
|
122
|
-
.map((child) =>
|
|
123
|
-
explore_escaped_name(checker, genericDict, importDict, child),
|
|
124
|
-
)
|
|
125
|
-
.join(", ")}>`
|
|
126
|
-
: name;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function explore_name(name: string, decl?: ts.Node): string {
|
|
130
|
-
return decl && ts.isModuleBlock(decl)
|
|
131
|
-
? explore_name(
|
|
132
|
-
`${decl.parent.name.getFullText().trim()}.${name}`,
|
|
133
|
-
decl.parent.parent,
|
|
134
|
-
)
|
|
135
|
-
: name;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
1
|
+
import { HashMap, HashSet } from "tstl";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { ITypeTuple } from "../structures/ITypeTuple";
|
|
5
|
+
import { GenericAnalyzer } from "./GenericAnalyzer";
|
|
6
|
+
|
|
7
|
+
export namespace ImportAnalyzer {
|
|
8
|
+
export interface IOutput {
|
|
9
|
+
features: [string, string[]][];
|
|
10
|
+
alias: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type Dictionary = HashMap<string, HashSet<string>>;
|
|
14
|
+
|
|
15
|
+
export function analyze(
|
|
16
|
+
checker: ts.TypeChecker,
|
|
17
|
+
genericDict: GenericAnalyzer.Dictionary,
|
|
18
|
+
importDict: Dictionary,
|
|
19
|
+
type: ts.Type,
|
|
20
|
+
): ITypeTuple | null {
|
|
21
|
+
type = get_type(checker, type);
|
|
22
|
+
explore_escaped_name(checker, genericDict, importDict, type);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
return {
|
|
26
|
+
type,
|
|
27
|
+
typeName: explore_escaped_name(checker, genericDict, importDict, type),
|
|
28
|
+
};
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* ---------------------------------------------------------
|
|
35
|
+
TYPE
|
|
36
|
+
--------------------------------------------------------- */
|
|
37
|
+
function get_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
|
|
38
|
+
const symbol: ts.Symbol | undefined = type.getSymbol();
|
|
39
|
+
return symbol && get_name(symbol) === "Promise"
|
|
40
|
+
? escape_promise(checker, type)
|
|
41
|
+
: type;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
|
|
45
|
+
const generic: readonly ts.Type[] = checker.getTypeArguments(
|
|
46
|
+
type as ts.TypeReference,
|
|
47
|
+
);
|
|
48
|
+
if (generic.length !== 1)
|
|
49
|
+
throw new Error(
|
|
50
|
+
"Error on ImportAnalyzer.analyze(): invalid promise type.",
|
|
51
|
+
);
|
|
52
|
+
return generic[0];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function get_name(symbol: ts.Symbol): string {
|
|
56
|
+
return explore_name(
|
|
57
|
+
symbol.escapedName.toString(),
|
|
58
|
+
symbol.getDeclarations()?.[0]?.parent,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* ---------------------------------------------------------
|
|
63
|
+
ESCAPED TEXT WITH IMPORT STATEMENTS
|
|
64
|
+
--------------------------------------------------------- */
|
|
65
|
+
function explore_escaped_name(
|
|
66
|
+
checker: ts.TypeChecker,
|
|
67
|
+
genericDict: GenericAnalyzer.Dictionary,
|
|
68
|
+
importDict: Dictionary,
|
|
69
|
+
type: ts.Type,
|
|
70
|
+
): string {
|
|
71
|
+
//----
|
|
72
|
+
// CONDITIONAL BRANCHES
|
|
73
|
+
//----
|
|
74
|
+
// DECOMPOSE GENERIC ARGUMENT
|
|
75
|
+
while (genericDict.has(type) === true) type = genericDict.get(type)!;
|
|
76
|
+
|
|
77
|
+
// PRIMITIVE
|
|
78
|
+
const symbol: ts.Symbol | undefined = type.aliasSymbol ?? type.getSymbol();
|
|
79
|
+
|
|
80
|
+
// UNION OR INTERSECT
|
|
81
|
+
if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
|
|
82
|
+
const joiner: string = type.isIntersection() ? " & " : " | ";
|
|
83
|
+
return type.types
|
|
84
|
+
.map((child) =>
|
|
85
|
+
explore_escaped_name(checker, genericDict, importDict, child),
|
|
86
|
+
)
|
|
87
|
+
.join(joiner);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// NO SYMBOL
|
|
91
|
+
else if (symbol === undefined)
|
|
92
|
+
return checker.typeToString(
|
|
93
|
+
type,
|
|
94
|
+
undefined,
|
|
95
|
+
ts.TypeFormatFlags.NoTruncation,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
//----
|
|
99
|
+
// SPECIALIZATION
|
|
100
|
+
//----
|
|
101
|
+
const name: string = get_name(symbol);
|
|
102
|
+
const sourceFile: ts.SourceFile | undefined =
|
|
103
|
+
symbol.declarations?.[0]?.getSourceFile();
|
|
104
|
+
if (sourceFile === undefined) return name;
|
|
105
|
+
|
|
106
|
+
if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
|
|
107
|
+
const set: HashSet<string> = importDict.take(
|
|
108
|
+
sourceFile.fileName,
|
|
109
|
+
() => new HashSet(),
|
|
110
|
+
);
|
|
111
|
+
set.insert(name.split(".")[0]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// CHECK GENERIC
|
|
115
|
+
const generic: readonly ts.Type[] = type.aliasSymbol
|
|
116
|
+
? type.aliasTypeArguments || []
|
|
117
|
+
: checker.getTypeArguments(type as ts.TypeReference);
|
|
118
|
+
return generic.length
|
|
119
|
+
? name === "Promise"
|
|
120
|
+
? explore_escaped_name(checker, genericDict, importDict, generic[0])
|
|
121
|
+
: `${name}<${generic
|
|
122
|
+
.map((child) =>
|
|
123
|
+
explore_escaped_name(checker, genericDict, importDict, child),
|
|
124
|
+
)
|
|
125
|
+
.join(", ")}>`
|
|
126
|
+
: name;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function explore_name(name: string, decl?: ts.Node): string {
|
|
130
|
+
return decl && ts.isModuleBlock(decl)
|
|
131
|
+
? explore_name(
|
|
132
|
+
`${decl.parent.name.getFullText().trim()}.${name}`,
|
|
133
|
+
decl.parent.parent,
|
|
134
|
+
)
|
|
135
|
+
: name;
|
|
136
|
+
}
|
|
137
|
+
}
|