@nestia/sdk 3.0.5 → 3.1.0-dev.20240426
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/NestiaSdkApplication.d.ts +1 -0
- package/lib/NestiaSdkApplication.js +17 -17
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/analyses/AccessorAnalyzer.d.ts +3 -2
- package/lib/analyses/AccessorAnalyzer.js.map +1 -1
- package/lib/analyses/ExceptionAnalyzer.d.ts +11 -3
- package/lib/analyses/ExceptionAnalyzer.js +23 -18
- package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
- package/lib/analyses/GenericAnalyzer.d.ts +1 -0
- package/lib/analyses/ImportAnalyzer.d.ts +6 -1
- package/lib/analyses/ImportAnalyzer.js +27 -29
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/PathAnalyzer.d.ts +0 -5
- package/lib/analyses/PathAnalyzer.js +0 -32
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/{ReflectAnalyzer.d.ts → ReflectControllerAnalyzer.d.ts} +3 -4
- package/lib/analyses/ReflectControllerAnalyzer.js +145 -0
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +10 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +224 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectMetadataAnalyzer.d.ts +8 -0
- package/lib/analyses/ReflectMetadataAnalyzer.js +34 -0
- package/lib/analyses/ReflectMetadataAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.d.ts +10 -0
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +78 -0
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -0
- package/lib/analyses/SecurityAnalyzer.js +1 -1
- package/lib/analyses/SecurityAnalyzer.js.map +1 -1
- package/lib/analyses/TypedControllerAnalyzer.d.ts +9 -0
- package/lib/analyses/TypedControllerAnalyzer.js +77 -0
- package/lib/analyses/TypedControllerAnalyzer.js.map +1 -0
- package/lib/analyses/TypedHttpOperationAnalyzer.d.ts +16 -0
- package/lib/analyses/TypedHttpOperationAnalyzer.js +251 -0
- package/lib/analyses/TypedHttpOperationAnalyzer.js.map +1 -0
- package/lib/analyses/TypedWebSocketOperationAnalyzer.d.ts +16 -0
- package/lib/analyses/TypedWebSocketOperationAnalyzer.js +218 -0
- package/lib/analyses/TypedWebSocketOperationAnalyzer.js.map +1 -0
- package/lib/executable/internal/NestiaConfigLoader.d.ts +1 -0
- package/lib/generates/CloneGenerator.d.ts +3 -4
- package/lib/generates/CloneGenerator.js +8 -8
- package/lib/generates/CloneGenerator.js.map +1 -1
- package/lib/generates/E2eGenerator.d.ts +3 -4
- package/lib/generates/E2eGenerator.js +7 -7
- package/lib/generates/E2eGenerator.js.map +1 -1
- package/lib/generates/SdkGenerator.d.ts +4 -4
- package/lib/generates/SdkGenerator.js +8 -8
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.d.ts +5 -2
- package/lib/generates/SwaggerGenerator.js +15 -13
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.d.ts +4 -5
- package/lib/generates/internal/E2eFileProgrammer.js +13 -12
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/FilePrinter.d.ts +1 -0
- package/lib/generates/internal/ImportDictionary.d.ts +1 -0
- package/lib/generates/internal/SdkAliasCollection.d.ts +9 -8
- package/lib/generates/internal/SdkAliasCollection.js +20 -20
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkDistributionComposer.d.ts +1 -1
- package/lib/generates/internal/SdkDistributionComposer.js +36 -2
- package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.d.ts +4 -4
- package/lib/generates/internal/SdkFileProgrammer.js +10 -7
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +13 -0
- package/lib/generates/internal/{SdkCloneProgrammer.js → SdkHttpCloneProgrammer.js} +14 -14
- package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +12 -0
- package/lib/generates/internal/{SdkFunctionProgrammer.js → SdkHttpFunctionProgrammer.js} +12 -12
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +12 -0
- package/lib/generates/internal/{SdkNamespaceProgrammer.js → SdkHttpNamespaceProgrammer.js} +26 -26
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpRouteProgrammer.d.ts +8 -0
- package/lib/generates/internal/{SdkRouteProgrammer.js → SdkHttpRouteProgrammer.js} +11 -11
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +13 -0
- package/lib/generates/internal/{SdkSimulationProgrammer.js → SdkHttpSimulationProgrammer.js} +18 -18
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkRouteDirectory.d.ts +3 -2
- package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
- package/lib/generates/internal/SdkTypeProgrammer.d.ts +4 -3
- package/lib/generates/internal/SdkTypeProgrammer.js +33 -33
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +8 -0
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +115 -0
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +8 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +79 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +6 -5
- package/lib/generates/internal/SwaggerSchemaGenerator.js +3 -1
- package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
- package/lib/structures/INestiaProject.d.ts +1 -0
- package/lib/structures/IReflectController.d.ts +15 -0
- package/lib/structures/{IRoute.js → IReflectController.js} +1 -1
- package/lib/structures/IReflectController.js.map +1 -0
- package/lib/structures/{IController.d.ts → IReflectHttpOperation.d.ts} +15 -25
- package/lib/structures/IReflectHttpOperation.js +3 -0
- package/lib/structures/IReflectHttpOperation.js.map +1 -0
- package/lib/structures/IReflectWebSocketOperation.d.ts +16 -0
- package/lib/structures/IReflectWebSocketOperation.js +3 -0
- package/lib/structures/IReflectWebSocketOperation.js.map +1 -0
- package/lib/structures/ISwaggerError.d.ts +2 -2
- package/lib/structures/ITypeTuple.d.ts +1 -0
- package/lib/structures/{IRoute.d.ts → ITypedHttpRoute.d.ts} +12 -12
- package/lib/structures/{IController.js → ITypedHttpRoute.js} +1 -1
- package/lib/structures/ITypedHttpRoute.js.map +1 -0
- package/lib/structures/ITypedWebSocketRoute.d.ts +54 -0
- package/lib/structures/ITypedWebSocketRoute.js +3 -0
- package/lib/structures/ITypedWebSocketRoute.js.map +1 -0
- package/lib/structures/TypeEntry.d.ts +1 -0
- package/lib/utils/VersioningStrategy.d.ts +6 -0
- package/lib/utils/VersioningStrategy.js +22 -0
- package/lib/utils/VersioningStrategy.js.map +1 -0
- package/package.json +8 -6
- package/src/NestiaSdkApplication.ts +36 -34
- package/src/analyses/AccessorAnalyzer.ts +12 -5
- package/src/analyses/ExceptionAnalyzer.ts +49 -39
- package/src/analyses/ImportAnalyzer.ts +123 -104
- package/src/analyses/PathAnalyzer.ts +0 -41
- package/src/analyses/ReflectControllerAnalyzer.ts +155 -0
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +290 -0
- package/src/analyses/ReflectMetadataAnalyzer.ts +53 -0
- package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +96 -0
- package/src/analyses/SecurityAnalyzer.ts +2 -1
- package/src/analyses/TypedControllerAnalyzer.ts +92 -0
- package/src/analyses/TypedHttpOperationAnalyzer.ts +352 -0
- package/src/analyses/TypedWebSocketOperationAnalyzer.ts +368 -0
- package/src/generates/CloneGenerator.ts +17 -15
- package/src/generates/E2eGenerator.ts +10 -12
- package/src/generates/SdkGenerator.ts +19 -12
- package/src/generates/SwaggerGenerator.ts +31 -21
- package/src/generates/internal/E2eFileProgrammer.ts +20 -24
- package/src/generates/internal/SdkAliasCollection.ts +38 -33
- package/src/generates/internal/SdkDistributionComposer.ts +13 -4
- package/src/generates/internal/SdkFileProgrammer.ts +17 -13
- package/src/generates/internal/{SdkCloneProgrammer.ts → SdkHttpCloneProgrammer.ts} +14 -15
- package/src/generates/internal/{SdkFunctionProgrammer.ts → SdkHttpFunctionProgrammer.ts} +24 -23
- package/src/generates/internal/{SdkNamespaceProgrammer.ts → SdkHttpNamespaceProgrammer.ts} +44 -49
- package/src/generates/internal/{SdkRouteProgrammer.ts → SdkHttpRouteProgrammer.ts} +12 -13
- package/src/generates/internal/{SdkSimulationProgrammer.ts → SdkHttpSimulationProgrammer.ts} +23 -25
- package/src/generates/internal/SdkRouteDirectory.ts +3 -2
- package/src/generates/internal/SdkTypeProgrammer.ts +43 -37
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +378 -0
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +248 -0
- package/src/generates/internal/SwaggerSchemaGenerator.ts +26 -21
- package/src/structures/IReflectController.ts +17 -0
- package/src/structures/{IController.ts → IReflectHttpOperation.ts} +78 -94
- package/src/structures/IReflectWebSocketOperation.ts +17 -0
- package/src/structures/ISwaggerError.ts +2 -2
- package/src/structures/{IRoute.ts → ITypedHttpRoute.ts} +14 -12
- package/src/structures/ITypedWebSocketRoute.ts +67 -0
- package/src/utils/VersioningStrategy.ts +28 -0
- package/lib/analyses/ControllerAnalyzer.d.ts +0 -7
- package/lib/analyses/ControllerAnalyzer.js +0 -269
- package/lib/analyses/ControllerAnalyzer.js.map +0 -1
- package/lib/analyses/ReflectAnalyzer.js +0 -377
- package/lib/analyses/ReflectAnalyzer.js.map +0 -1
- package/lib/generates/internal/SdkCloneProgrammer.d.ts +0 -12
- package/lib/generates/internal/SdkCloneProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkFunctionProgrammer.d.ts +0 -11
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +0 -11
- package/lib/generates/internal/SdkNamespaceProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkRouteProgrammer.d.ts +0 -7
- package/lib/generates/internal/SdkRouteProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkSimulationProgrammer.d.ts +0 -12
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +0 -1
- package/lib/structures/IController.js.map +0 -1
- package/lib/structures/IRoute.js.map +0 -1
- package/src/analyses/ControllerAnalyzer.ts +0 -402
- package/src/analyses/ReflectAnalyzer.ts +0 -471
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { RequestMethod } from "@nestjs/common";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { HashMap } from "tstl";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { CommentFactory } from "typia/lib/factories/CommentFactory";
|
|
6
|
+
|
|
7
|
+
import { IErrorReport } from "../structures/IErrorReport";
|
|
8
|
+
import { INestiaProject } from "../structures/INestiaProject";
|
|
9
|
+
import { IReflectController } from "../structures/IReflectController";
|
|
10
|
+
import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
|
|
11
|
+
import { ITypeTuple } from "../structures/ITypeTuple";
|
|
12
|
+
import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
|
|
13
|
+
import { PathUtil } from "../utils/PathUtil";
|
|
14
|
+
import { VersioningStrategy } from "../utils/VersioningStrategy";
|
|
15
|
+
import { ExceptionAnalyzer } from "./ExceptionAnalyzer";
|
|
16
|
+
import { GenericAnalyzer } from "./GenericAnalyzer";
|
|
17
|
+
import { ImportAnalyzer } from "./ImportAnalyzer";
|
|
18
|
+
import { PathAnalyzer } from "./PathAnalyzer";
|
|
19
|
+
import { SecurityAnalyzer } from "./SecurityAnalyzer";
|
|
20
|
+
|
|
21
|
+
export namespace TypedHttpOperationAnalyzer {
|
|
22
|
+
export const analyze =
|
|
23
|
+
(project: INestiaProject) =>
|
|
24
|
+
(props: {
|
|
25
|
+
controller: IReflectController;
|
|
26
|
+
operation: IReflectHttpOperation;
|
|
27
|
+
declaration: ts.MethodDeclaration;
|
|
28
|
+
symbol: ts.Symbol;
|
|
29
|
+
generics: GenericAnalyzer.Dictionary;
|
|
30
|
+
}): ITypedHttpRoute[] => {
|
|
31
|
+
// CHECK TYPE
|
|
32
|
+
const type: ts.Type = project.checker.getTypeOfSymbolAtLocation(
|
|
33
|
+
props.symbol,
|
|
34
|
+
props.symbol.valueDeclaration!,
|
|
35
|
+
);
|
|
36
|
+
const signature: ts.Signature | undefined =
|
|
37
|
+
project.checker.getSignaturesOfType(type, ts.SignatureKind.Call)[0];
|
|
38
|
+
if (signature === undefined) {
|
|
39
|
+
project.errors.push({
|
|
40
|
+
file: props.controller.file,
|
|
41
|
+
controller: props.controller.name,
|
|
42
|
+
function: props.operation.name,
|
|
43
|
+
message: "unable to get the type signature.",
|
|
44
|
+
});
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// SKIP @IGNORE TAG
|
|
49
|
+
const jsDocTags = signature.getJsDocTags();
|
|
50
|
+
if (jsDocTags.some((tag) => tag.name === "ignore")) return [];
|
|
51
|
+
|
|
52
|
+
// EXPLORE CHILDREN TYPES
|
|
53
|
+
const importDict: ImportAnalyzer.Dictionary = new HashMap();
|
|
54
|
+
const parameters: Array<ITypedHttpRoute.IParameter | null> =
|
|
55
|
+
props.operation.parameters.map(
|
|
56
|
+
(param) =>
|
|
57
|
+
_Analyze_parameter(project)({
|
|
58
|
+
generics: props.generics,
|
|
59
|
+
imports: importDict,
|
|
60
|
+
controller: props.controller,
|
|
61
|
+
function: props.operation.name,
|
|
62
|
+
parameter: param,
|
|
63
|
+
symbol: signature.getParameters()[param.index],
|
|
64
|
+
})!,
|
|
65
|
+
);
|
|
66
|
+
const outputType: ITypeTuple | null = ImportAnalyzer.analyze(
|
|
67
|
+
project.checker,
|
|
68
|
+
)({
|
|
69
|
+
generics: props.generics,
|
|
70
|
+
imports: importDict,
|
|
71
|
+
type: signature.getReturnType(),
|
|
72
|
+
});
|
|
73
|
+
if (
|
|
74
|
+
outputType === null ||
|
|
75
|
+
(project.config.clone !== true &&
|
|
76
|
+
(outputType.typeName === "__type" ||
|
|
77
|
+
outputType.typeName === "__object"))
|
|
78
|
+
) {
|
|
79
|
+
project.errors.push({
|
|
80
|
+
file: props.controller.file,
|
|
81
|
+
controller: props.controller.name,
|
|
82
|
+
function: props.operation.name,
|
|
83
|
+
message: "implicit (unnamed) return type.",
|
|
84
|
+
});
|
|
85
|
+
return [];
|
|
86
|
+
} else if (
|
|
87
|
+
props.operation.method === "HEAD" &&
|
|
88
|
+
outputType.typeName !== "void" &&
|
|
89
|
+
outputType.typeName !== "undefined"
|
|
90
|
+
) {
|
|
91
|
+
project.errors.push({
|
|
92
|
+
file: props.controller.file,
|
|
93
|
+
controller: props.controller.name,
|
|
94
|
+
function: props.operation.name,
|
|
95
|
+
message: `HEAD method must return void type.`,
|
|
96
|
+
});
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const exceptions = ExceptionAnalyzer.analyze(project)({
|
|
101
|
+
generics: props.generics,
|
|
102
|
+
imports: project.config.propagate === true ? importDict : new HashMap(),
|
|
103
|
+
controller: props.controller,
|
|
104
|
+
operation: props.operation,
|
|
105
|
+
declaration: props.declaration,
|
|
106
|
+
});
|
|
107
|
+
const imports: [string, string[]][] = importDict
|
|
108
|
+
.toJSON()
|
|
109
|
+
.map((pair) => [pair.first, pair.second.toJSON()]);
|
|
110
|
+
|
|
111
|
+
// CONSIDER SECURITY TAGS
|
|
112
|
+
const security: Record<string, string[]>[] = SecurityAnalyzer.merge(
|
|
113
|
+
...props.controller.security,
|
|
114
|
+
...props.operation.security,
|
|
115
|
+
...jsDocTags
|
|
116
|
+
.filter((tag) => tag.name === "security")
|
|
117
|
+
.map((tag) =>
|
|
118
|
+
tag.text === undefined
|
|
119
|
+
? [{}]
|
|
120
|
+
: tag.text.map((text) => {
|
|
121
|
+
const line: string[] = text.text
|
|
122
|
+
.split(" ")
|
|
123
|
+
.filter((s) => s.trim())
|
|
124
|
+
.filter((s) => !!s.length);
|
|
125
|
+
if (line.length === 0) return {};
|
|
126
|
+
return {
|
|
127
|
+
[line[0]]: line.slice(1),
|
|
128
|
+
};
|
|
129
|
+
}),
|
|
130
|
+
)
|
|
131
|
+
.flat(),
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
// CONSTRUCT COMMON DATA
|
|
135
|
+
const common: Omit<ITypedHttpRoute, "path" | "accessors"> = {
|
|
136
|
+
...props.operation,
|
|
137
|
+
controller: props.controller,
|
|
138
|
+
parameters: parameters.filter(
|
|
139
|
+
(p) => p !== null,
|
|
140
|
+
) as ITypedHttpRoute.IParameter[],
|
|
141
|
+
output: {
|
|
142
|
+
type: outputType.type,
|
|
143
|
+
typeName: outputType.typeName,
|
|
144
|
+
contentType: props.operation.contentType,
|
|
145
|
+
},
|
|
146
|
+
imports,
|
|
147
|
+
status: props.operation.status,
|
|
148
|
+
location: (() => {
|
|
149
|
+
const file = props.declaration.getSourceFile();
|
|
150
|
+
const { line, character } = file.getLineAndCharacterOfPosition(
|
|
151
|
+
props.declaration.pos,
|
|
152
|
+
);
|
|
153
|
+
return `${path.relative(process.cwd(), file.fileName)}:${line + 1}:${
|
|
154
|
+
character + 1
|
|
155
|
+
}`;
|
|
156
|
+
})(),
|
|
157
|
+
description: CommentFactory.description(props.symbol),
|
|
158
|
+
operationId: jsDocTags
|
|
159
|
+
.find(({ name }) => name === "operationId")
|
|
160
|
+
?.text?.[0].text.split(" ")[0]
|
|
161
|
+
.trim(),
|
|
162
|
+
jsDocTags: jsDocTags,
|
|
163
|
+
setHeaders: jsDocTags
|
|
164
|
+
.filter(
|
|
165
|
+
(t) =>
|
|
166
|
+
t.text?.length &&
|
|
167
|
+
t.text[0].text &&
|
|
168
|
+
(t.name === "setHeader" || t.name === "assignHeaders"),
|
|
169
|
+
)
|
|
170
|
+
.map((t) =>
|
|
171
|
+
t.name === "setHeader"
|
|
172
|
+
? {
|
|
173
|
+
type: "setter",
|
|
174
|
+
source: t.text![0].text.split(" ")[0].trim(),
|
|
175
|
+
target: t.text![0].text.split(" ")[1]?.trim(),
|
|
176
|
+
}
|
|
177
|
+
: {
|
|
178
|
+
type: "assigner",
|
|
179
|
+
source: t.text![0].text,
|
|
180
|
+
},
|
|
181
|
+
),
|
|
182
|
+
security,
|
|
183
|
+
exceptions,
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// CONFIGURE PATHS
|
|
187
|
+
const globalPrefix = project.input.globalPrefix ?? {
|
|
188
|
+
prefix: "",
|
|
189
|
+
};
|
|
190
|
+
const pathList: Set<string> = new Set();
|
|
191
|
+
const versions: string[] = VersioningStrategy.merge(project)([
|
|
192
|
+
...(props.controller.versions ?? []),
|
|
193
|
+
...(props.operation.versions ?? []),
|
|
194
|
+
]);
|
|
195
|
+
for (const v of versions)
|
|
196
|
+
for (const prefix of wrapPaths(props.controller.prefixes))
|
|
197
|
+
for (const cPath of wrapPaths(props.controller.paths))
|
|
198
|
+
for (const filePath of wrapPaths(props.operation.paths))
|
|
199
|
+
pathList.add(
|
|
200
|
+
PathAnalyzer.join(
|
|
201
|
+
globalPrefix.prefix,
|
|
202
|
+
v,
|
|
203
|
+
prefix,
|
|
204
|
+
cPath,
|
|
205
|
+
filePath,
|
|
206
|
+
),
|
|
207
|
+
);
|
|
208
|
+
return [...pathList]
|
|
209
|
+
.filter((path) => {
|
|
210
|
+
const escaped: string | null = PathAnalyzer.escape(path);
|
|
211
|
+
if (escaped === null) {
|
|
212
|
+
project.errors.push({
|
|
213
|
+
file: props.controller.file,
|
|
214
|
+
controller: props.controller.name,
|
|
215
|
+
function: props.operation.name,
|
|
216
|
+
message: `unable to escape the path "${path}".`,
|
|
217
|
+
});
|
|
218
|
+
return false;
|
|
219
|
+
} else if (Array.isArray(globalPrefix.exclude))
|
|
220
|
+
return globalPrefix.exclude.some((e) =>
|
|
221
|
+
typeof e === "string"
|
|
222
|
+
? !RegExp(e).test(path)
|
|
223
|
+
: RegExp(e.path).test(path) &&
|
|
224
|
+
(enumToMethod(e.method) === "all" ||
|
|
225
|
+
enumToMethod(e.method) ===
|
|
226
|
+
props.operation.method.toLowerCase()) &&
|
|
227
|
+
(e.version === undefined ||
|
|
228
|
+
versions.some((v) => v === e.version)),
|
|
229
|
+
);
|
|
230
|
+
return true;
|
|
231
|
+
})
|
|
232
|
+
.map((path) => ({
|
|
233
|
+
...common,
|
|
234
|
+
path: PathAnalyzer.escape(path)!,
|
|
235
|
+
accessors: [...PathUtil.accessors(path), props.operation.name],
|
|
236
|
+
}));
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const _Analyze_parameter =
|
|
240
|
+
(project: INestiaProject) =>
|
|
241
|
+
(props: {
|
|
242
|
+
generics: GenericAnalyzer.Dictionary;
|
|
243
|
+
imports: ImportAnalyzer.Dictionary;
|
|
244
|
+
controller: IReflectController;
|
|
245
|
+
function: string;
|
|
246
|
+
parameter: IReflectHttpOperation.IParameter;
|
|
247
|
+
symbol: ts.Symbol;
|
|
248
|
+
}): ITypedHttpRoute.IParameter | null => {
|
|
249
|
+
const type: ts.Type = project.checker.getTypeOfSymbolAtLocation(
|
|
250
|
+
props.symbol,
|
|
251
|
+
props.symbol.valueDeclaration!,
|
|
252
|
+
);
|
|
253
|
+
const name: string = props.symbol.getEscapedName().toString();
|
|
254
|
+
const optional: boolean = !!project.checker.symbolToParameterDeclaration(
|
|
255
|
+
props.symbol,
|
|
256
|
+
undefined,
|
|
257
|
+
undefined,
|
|
258
|
+
)?.questionToken;
|
|
259
|
+
|
|
260
|
+
const errors: IErrorReport[] = [];
|
|
261
|
+
|
|
262
|
+
// DO NOT SUPPORT BODY PARAMETER
|
|
263
|
+
if (
|
|
264
|
+
props.parameter.category === "body" &&
|
|
265
|
+
props.parameter.field !== undefined
|
|
266
|
+
)
|
|
267
|
+
errors.push({
|
|
268
|
+
file: props.controller.file,
|
|
269
|
+
controller: props.controller.name,
|
|
270
|
+
function: props.function,
|
|
271
|
+
message:
|
|
272
|
+
`nestia does not support body field specification. ` +
|
|
273
|
+
`Therefore, erase the "${name}" parameter and ` +
|
|
274
|
+
`re-define a new body decorator accepting full structured message.`,
|
|
275
|
+
});
|
|
276
|
+
if (optional === true && props.parameter.category !== "query")
|
|
277
|
+
errors.push({
|
|
278
|
+
file: props.controller.file,
|
|
279
|
+
controller: props.controller.name,
|
|
280
|
+
function: props.function,
|
|
281
|
+
message:
|
|
282
|
+
`nestia does not support optional parameter except query parameter. ` +
|
|
283
|
+
`Therefore, erase question mark on the "${name}" parameter, ` +
|
|
284
|
+
`or re-define a new method without the "${name}" parameter.`,
|
|
285
|
+
});
|
|
286
|
+
if (
|
|
287
|
+
optional === true &&
|
|
288
|
+
props.parameter.category === "query" &&
|
|
289
|
+
props.parameter.field === undefined
|
|
290
|
+
)
|
|
291
|
+
errors.push({
|
|
292
|
+
file: props.controller.file,
|
|
293
|
+
controller: props.controller.name,
|
|
294
|
+
function: props.function,
|
|
295
|
+
message:
|
|
296
|
+
`nestia does not support optional query parameter without field specification. ` +
|
|
297
|
+
`Therefore, erase question mark on the "${name}" parameter, ` +
|
|
298
|
+
`or re-define re-define parameters for each query parameters.`,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// GET TYPE NAME
|
|
302
|
+
const tuple: ITypeTuple | null = ImportAnalyzer.analyze(project.checker)({
|
|
303
|
+
generics: props.generics,
|
|
304
|
+
imports: props.imports,
|
|
305
|
+
type,
|
|
306
|
+
});
|
|
307
|
+
if (
|
|
308
|
+
tuple === null ||
|
|
309
|
+
(project.config.clone !== true &&
|
|
310
|
+
(tuple.typeName === "__type" || tuple.typeName === "__object"))
|
|
311
|
+
)
|
|
312
|
+
errors.push({
|
|
313
|
+
file: props.controller.file,
|
|
314
|
+
controller: props.controller.name,
|
|
315
|
+
function: props.function,
|
|
316
|
+
message: `implicit (unnamed) parameter type from "${name}".`,
|
|
317
|
+
});
|
|
318
|
+
if (errors.length) {
|
|
319
|
+
project.errors.push(...errors);
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
...props.parameter,
|
|
324
|
+
name,
|
|
325
|
+
optional,
|
|
326
|
+
type: tuple!.type,
|
|
327
|
+
typeName: tuple!.typeName,
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const enumToMethod = (v: RequestMethod) =>
|
|
333
|
+
v === RequestMethod.GET
|
|
334
|
+
? "get"
|
|
335
|
+
: v === RequestMethod.POST
|
|
336
|
+
? "post"
|
|
337
|
+
: v === RequestMethod.PUT
|
|
338
|
+
? "put"
|
|
339
|
+
: v === RequestMethod.DELETE
|
|
340
|
+
? "delete"
|
|
341
|
+
: v === RequestMethod.PATCH
|
|
342
|
+
? "patch"
|
|
343
|
+
: v === RequestMethod.ALL
|
|
344
|
+
? "all"
|
|
345
|
+
: v === RequestMethod.OPTIONS
|
|
346
|
+
? "options"
|
|
347
|
+
: v === RequestMethod.HEAD
|
|
348
|
+
? "head"
|
|
349
|
+
: "search";
|
|
350
|
+
|
|
351
|
+
const wrapPaths = (paths: string[]): string[] =>
|
|
352
|
+
paths.length === 0 ? [""] : paths;
|