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