@nestia/sdk 2.6.2 → 2.6.3
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/analyses/ControllerAnalyzer.js +3 -3
- package/lib/analyses/ControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ImportAnalyzer.d.ts +1 -2
- package/lib/analyses/ImportAnalyzer.js +2 -2
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectAnalyzer.js +2 -2
- package/lib/analyses/ReflectAnalyzer.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +4 -4
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.js +6 -8
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/structures/TypeEntry.js +2 -2
- package/lib/structures/TypeEntry.js.map +1 -1
- package/package.json +4 -4
- package/src/INestiaConfig.ts +248 -248
- package/src/NestiaSdkApplication.ts +255 -255
- package/src/analyses/ControllerAnalyzer.ts +402 -402
- package/src/analyses/ExceptionAnalyzer.ts +148 -148
- package/src/analyses/ImportAnalyzer.ts +1 -2
- package/src/analyses/ReflectAnalyzer.ts +463 -463
- package/src/analyses/SecurityAnalyzer.ts +24 -24
- package/src/generates/CloneGenerator.ts +62 -62
- package/src/generates/E2eGenerator.ts +66 -66
- package/src/generates/SdkGenerator.ts +84 -84
- package/src/generates/SwaggerGenerator.ts +446 -446
- package/src/generates/internal/E2eFileProgrammer.ts +182 -182
- package/src/generates/internal/FilePrinter.ts +53 -53
- package/src/generates/internal/ImportDictionary.ts +147 -149
- package/src/generates/internal/SdkAliasCollection.ts +152 -152
- package/src/generates/internal/SdkCloneProgrammer.ts +155 -155
- package/src/generates/internal/SdkFileProgrammer.ts +115 -115
- package/src/generates/internal/SdkFunctionProgrammer.ts +298 -298
- package/src/generates/internal/SdkImportWizard.ts +55 -55
- package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -510
- package/src/generates/internal/SdkRouteProgrammer.ts +83 -83
- package/src/generates/internal/SdkSimulationProgrammer.ts +365 -365
- package/src/generates/internal/SdkTypeProgrammer.ts +385 -385
- package/src/generates/internal/SwaggerSchemaGenerator.ts +438 -438
- package/src/structures/IController.ts +94 -94
- package/src/structures/IRoute.ts +53 -53
- package/src/structures/ISwagger.ts +91 -91
- package/src/structures/ISwaggerRoute.ts +54 -54
- package/src/structures/ISwaggerSecurityScheme.ts +65 -65
- package/src/structures/ParamCategory.ts +1 -1
- package/src/structures/TypeEntry.ts +1 -1
- package/src/utils/StringUtil.ts +6 -6
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
4
|
-
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
5
|
-
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
6
|
-
|
|
7
|
-
import { IController } from "../structures/IController";
|
|
8
|
-
import { INestiaProject } from "../structures/INestiaProject";
|
|
9
|
-
import { IRoute } from "../structures/IRoute";
|
|
10
|
-
import { ITypeTuple } from "../structures/ITypeTuple";
|
|
11
|
-
import { GenericAnalyzer } from "./GenericAnalyzer";
|
|
12
|
-
import { ImportAnalyzer } from "./ImportAnalyzer";
|
|
13
|
-
|
|
14
|
-
export namespace ExceptionAnalyzer {
|
|
15
|
-
export const analyze =
|
|
16
|
-
(project: INestiaProject) =>
|
|
17
|
-
(
|
|
18
|
-
genericDict: GenericAnalyzer.Dictionary,
|
|
19
|
-
importDict: ImportAnalyzer.Dictionary,
|
|
20
|
-
) =>
|
|
21
|
-
(controller: IController, func: IController.IFunction) =>
|
|
22
|
-
(
|
|
23
|
-
declaration: ts.MethodDeclaration,
|
|
24
|
-
): Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput> => {
|
|
25
|
-
const output: Record<
|
|
26
|
-
number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
27
|
-
IRoute.IOutput
|
|
28
|
-
> = {} as any;
|
|
29
|
-
for (const decorator of declaration.modifiers ?? [])
|
|
30
|
-
if (ts.isDecorator(decorator))
|
|
31
|
-
analyzeTyped(project)(genericDict, importDict)(controller, func)(
|
|
32
|
-
output,
|
|
33
|
-
)(decorator);
|
|
34
|
-
return output;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const analyzeTyped =
|
|
38
|
-
(project: INestiaProject) =>
|
|
39
|
-
(
|
|
40
|
-
genericDict: GenericAnalyzer.Dictionary,
|
|
41
|
-
importDict: ImportAnalyzer.Dictionary,
|
|
42
|
-
) =>
|
|
43
|
-
(controller: IController, func: IController.IFunction) =>
|
|
44
|
-
(output: Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput>) =>
|
|
45
|
-
(decorator: ts.Decorator): boolean => {
|
|
46
|
-
// CHECK DECORATOR
|
|
47
|
-
if (!ts.isCallExpression(decorator.expression)) return false;
|
|
48
|
-
else if ((decorator.expression.typeArguments ?? []).length !== 1)
|
|
49
|
-
return false;
|
|
50
|
-
|
|
51
|
-
// CHECK SIGNATURE
|
|
52
|
-
const signature: ts.Signature | undefined =
|
|
53
|
-
project.checker.getResolvedSignature(decorator.expression);
|
|
54
|
-
if (!signature || !signature.declaration) return false;
|
|
55
|
-
else if (
|
|
56
|
-
path
|
|
57
|
-
.resolve(signature.declaration.getSourceFile().fileName)
|
|
58
|
-
.indexOf(TYPED_EXCEPTION_PATH) === -1
|
|
59
|
-
)
|
|
60
|
-
return false;
|
|
61
|
-
|
|
62
|
-
// GET TYPE INFO
|
|
63
|
-
const status: string | null = getStatus(project.checker)(
|
|
64
|
-
decorator.expression.arguments[0] ?? null,
|
|
65
|
-
);
|
|
66
|
-
if (status === null) return false;
|
|
67
|
-
|
|
68
|
-
const node: ts.TypeNode = decorator.expression.typeArguments![0];
|
|
69
|
-
const type: ts.Type = project.checker.getTypeFromTypeNode(node);
|
|
70
|
-
if (type.isTypeParameter()) {
|
|
71
|
-
project.errors.push({
|
|
72
|
-
file: controller.file,
|
|
73
|
-
controller: controller.name,
|
|
74
|
-
function: func.name,
|
|
75
|
-
message: "TypedException() without generic argument specification.",
|
|
76
|
-
});
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const tuple: ITypeTuple | null = ImportAnalyzer.analyze(
|
|
81
|
-
project.checker,
|
|
82
|
-
genericDict,
|
|
83
|
-
importDict,
|
|
84
|
-
type,
|
|
85
|
-
);
|
|
86
|
-
if (
|
|
87
|
-
tuple === null ||
|
|
88
|
-
(project.config.clone !== true &&
|
|
89
|
-
(tuple.typeName === "__type" || tuple.typeName === "__object"))
|
|
90
|
-
) {
|
|
91
|
-
project.errors.push({
|
|
92
|
-
file: controller.file,
|
|
93
|
-
controller: controller.name,
|
|
94
|
-
function: func.name,
|
|
95
|
-
message: "TypeException() with implicit (unnamed) type.",
|
|
96
|
-
});
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// DO ASSIGN
|
|
101
|
-
const matched: IController.IException[] = Object.entries(func.exceptions)
|
|
102
|
-
.filter(([key]) => status === key)
|
|
103
|
-
.map(([_key, value]) => value);
|
|
104
|
-
for (const m of matched)
|
|
105
|
-
output[m.status] = {
|
|
106
|
-
type: tuple.type,
|
|
107
|
-
typeName: tuple.typeName,
|
|
108
|
-
contentType: "application/json",
|
|
109
|
-
description: m.description,
|
|
110
|
-
};
|
|
111
|
-
return true;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const getStatus =
|
|
115
|
-
(checker: ts.TypeChecker) =>
|
|
116
|
-
(expression: ts.Expression | null): string | null => {
|
|
117
|
-
if (expression === null) return null;
|
|
118
|
-
|
|
119
|
-
const type: ts.Type = checker.getTypeAtLocation(expression);
|
|
120
|
-
const result = MetadataFactory.analyze(checker)({
|
|
121
|
-
escape: true,
|
|
122
|
-
constant: true,
|
|
123
|
-
absorb: true,
|
|
124
|
-
})(new MetadataCollection())(type);
|
|
125
|
-
if (false === result.success) return null;
|
|
126
|
-
|
|
127
|
-
const meta: Metadata = result.data;
|
|
128
|
-
if (meta.constants.length === 1)
|
|
129
|
-
return meta.constants[0].values[0].toString();
|
|
130
|
-
else if (meta.escaped && meta.escaped.returns.constants.length === 1)
|
|
131
|
-
return meta.escaped.returns.constants[0].values[0].toString();
|
|
132
|
-
else if (ts.isStringLiteral(expression)) return expression.text;
|
|
133
|
-
else if (ts.isNumericLiteral(expression)) {
|
|
134
|
-
const value: number = Number(expression.text.split("_").join(""));
|
|
135
|
-
if (false === isNaN(value)) return value.toString();
|
|
136
|
-
}
|
|
137
|
-
return null;
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const TYPED_EXCEPTION_PATH = path.join(
|
|
142
|
-
"node_modules",
|
|
143
|
-
"@nestia",
|
|
144
|
-
"core",
|
|
145
|
-
"lib",
|
|
146
|
-
"decorators",
|
|
147
|
-
"TypedException.d.ts",
|
|
148
|
-
);
|
|
1
|
+
import path from "path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
4
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
5
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
6
|
+
|
|
7
|
+
import { IController } from "../structures/IController";
|
|
8
|
+
import { INestiaProject } from "../structures/INestiaProject";
|
|
9
|
+
import { IRoute } from "../structures/IRoute";
|
|
10
|
+
import { ITypeTuple } from "../structures/ITypeTuple";
|
|
11
|
+
import { GenericAnalyzer } from "./GenericAnalyzer";
|
|
12
|
+
import { ImportAnalyzer } from "./ImportAnalyzer";
|
|
13
|
+
|
|
14
|
+
export namespace ExceptionAnalyzer {
|
|
15
|
+
export const analyze =
|
|
16
|
+
(project: INestiaProject) =>
|
|
17
|
+
(
|
|
18
|
+
genericDict: GenericAnalyzer.Dictionary,
|
|
19
|
+
importDict: ImportAnalyzer.Dictionary,
|
|
20
|
+
) =>
|
|
21
|
+
(controller: IController, func: IController.IFunction) =>
|
|
22
|
+
(
|
|
23
|
+
declaration: ts.MethodDeclaration,
|
|
24
|
+
): Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput> => {
|
|
25
|
+
const output: Record<
|
|
26
|
+
number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
27
|
+
IRoute.IOutput
|
|
28
|
+
> = {} as any;
|
|
29
|
+
for (const decorator of declaration.modifiers ?? [])
|
|
30
|
+
if (ts.isDecorator(decorator))
|
|
31
|
+
analyzeTyped(project)(genericDict, importDict)(controller, func)(
|
|
32
|
+
output,
|
|
33
|
+
)(decorator);
|
|
34
|
+
return output;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const analyzeTyped =
|
|
38
|
+
(project: INestiaProject) =>
|
|
39
|
+
(
|
|
40
|
+
genericDict: GenericAnalyzer.Dictionary,
|
|
41
|
+
importDict: ImportAnalyzer.Dictionary,
|
|
42
|
+
) =>
|
|
43
|
+
(controller: IController, func: IController.IFunction) =>
|
|
44
|
+
(output: Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput>) =>
|
|
45
|
+
(decorator: ts.Decorator): boolean => {
|
|
46
|
+
// CHECK DECORATOR
|
|
47
|
+
if (!ts.isCallExpression(decorator.expression)) return false;
|
|
48
|
+
else if ((decorator.expression.typeArguments ?? []).length !== 1)
|
|
49
|
+
return false;
|
|
50
|
+
|
|
51
|
+
// CHECK SIGNATURE
|
|
52
|
+
const signature: ts.Signature | undefined =
|
|
53
|
+
project.checker.getResolvedSignature(decorator.expression);
|
|
54
|
+
if (!signature || !signature.declaration) return false;
|
|
55
|
+
else if (
|
|
56
|
+
path
|
|
57
|
+
.resolve(signature.declaration.getSourceFile().fileName)
|
|
58
|
+
.indexOf(TYPED_EXCEPTION_PATH) === -1
|
|
59
|
+
)
|
|
60
|
+
return false;
|
|
61
|
+
|
|
62
|
+
// GET TYPE INFO
|
|
63
|
+
const status: string | null = getStatus(project.checker)(
|
|
64
|
+
decorator.expression.arguments[0] ?? null,
|
|
65
|
+
);
|
|
66
|
+
if (status === null) return false;
|
|
67
|
+
|
|
68
|
+
const node: ts.TypeNode = decorator.expression.typeArguments![0];
|
|
69
|
+
const type: ts.Type = project.checker.getTypeFromTypeNode(node);
|
|
70
|
+
if (type.isTypeParameter()) {
|
|
71
|
+
project.errors.push({
|
|
72
|
+
file: controller.file,
|
|
73
|
+
controller: controller.name,
|
|
74
|
+
function: func.name,
|
|
75
|
+
message: "TypedException() without generic argument specification.",
|
|
76
|
+
});
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const tuple: ITypeTuple | null = ImportAnalyzer.analyze(
|
|
81
|
+
project.checker,
|
|
82
|
+
genericDict,
|
|
83
|
+
importDict,
|
|
84
|
+
type,
|
|
85
|
+
);
|
|
86
|
+
if (
|
|
87
|
+
tuple === null ||
|
|
88
|
+
(project.config.clone !== true &&
|
|
89
|
+
(tuple.typeName === "__type" || tuple.typeName === "__object"))
|
|
90
|
+
) {
|
|
91
|
+
project.errors.push({
|
|
92
|
+
file: controller.file,
|
|
93
|
+
controller: controller.name,
|
|
94
|
+
function: func.name,
|
|
95
|
+
message: "TypeException() with implicit (unnamed) type.",
|
|
96
|
+
});
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// DO ASSIGN
|
|
101
|
+
const matched: IController.IException[] = Object.entries(func.exceptions)
|
|
102
|
+
.filter(([key]) => status === key)
|
|
103
|
+
.map(([_key, value]) => value);
|
|
104
|
+
for (const m of matched)
|
|
105
|
+
output[m.status] = {
|
|
106
|
+
type: tuple.type,
|
|
107
|
+
typeName: tuple.typeName,
|
|
108
|
+
contentType: "application/json",
|
|
109
|
+
description: m.description,
|
|
110
|
+
};
|
|
111
|
+
return true;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const getStatus =
|
|
115
|
+
(checker: ts.TypeChecker) =>
|
|
116
|
+
(expression: ts.Expression | null): string | null => {
|
|
117
|
+
if (expression === null) return null;
|
|
118
|
+
|
|
119
|
+
const type: ts.Type = checker.getTypeAtLocation(expression);
|
|
120
|
+
const result = MetadataFactory.analyze(checker)({
|
|
121
|
+
escape: true,
|
|
122
|
+
constant: true,
|
|
123
|
+
absorb: true,
|
|
124
|
+
})(new MetadataCollection())(type);
|
|
125
|
+
if (false === result.success) return null;
|
|
126
|
+
|
|
127
|
+
const meta: Metadata = result.data;
|
|
128
|
+
if (meta.constants.length === 1)
|
|
129
|
+
return meta.constants[0].values[0].toString();
|
|
130
|
+
else if (meta.escaped && meta.escaped.returns.constants.length === 1)
|
|
131
|
+
return meta.escaped.returns.constants[0].values[0].toString();
|
|
132
|
+
else if (ts.isStringLiteral(expression)) return expression.text;
|
|
133
|
+
else if (ts.isNumericLiteral(expression)) {
|
|
134
|
+
const value: number = Number(expression.text.split("_").join(""));
|
|
135
|
+
if (false === isNaN(value)) return value.toString();
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const TYPED_EXCEPTION_PATH = path.join(
|
|
142
|
+
"node_modules",
|
|
143
|
+
"@nestia",
|
|
144
|
+
"core",
|
|
145
|
+
"lib",
|
|
146
|
+
"decorators",
|
|
147
|
+
"TypedException.d.ts",
|
|
148
|
+
);
|