@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
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { ROUTE_ARGS_METADATA } from "@nestjs/common/constants";
|
|
2
|
+
import { RouteParamtypes } from "@nestjs/common/enums/route-paramtypes.enum";
|
|
3
|
+
import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
|
|
4
|
+
import { HttpFormDataProgrammer } from "typia/lib/programmers/http/HttpFormDataProgrammer";
|
|
5
|
+
import { HttpHeadersProgrammer } from "typia/lib/programmers/http/HttpHeadersProgrammer";
|
|
6
|
+
import { HttpParameterProgrammer } from "typia/lib/programmers/http/HttpParameterProgrammer";
|
|
7
|
+
import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
|
|
8
|
+
|
|
9
|
+
import { IReflectController } from "../structures/IReflectController";
|
|
10
|
+
import { IReflectHttpOperationParameter } from "../structures/IReflectHttpOperationParameter";
|
|
11
|
+
import { IReflectOperationError } from "../structures/IReflectOperationError";
|
|
12
|
+
import { IReflectTypeImport } from "../structures/IReflectTypeImport";
|
|
13
|
+
import { IOperationMetadata } from "../transformers/IOperationMetadata";
|
|
14
|
+
import { TextPlainValidator } from "../transformers/TextPlainValidator";
|
|
15
|
+
|
|
16
|
+
export namespace ReflectHttpOperationParameterAnalyzer {
|
|
17
|
+
export interface IContext {
|
|
18
|
+
controller: IReflectController;
|
|
19
|
+
function: Function;
|
|
20
|
+
functionName: string;
|
|
21
|
+
httpMethod: string;
|
|
22
|
+
metadata: IOperationMetadata;
|
|
23
|
+
errors: IReflectOperationError[];
|
|
24
|
+
}
|
|
25
|
+
export const analyze = (ctx: IContext): IReflectHttpOperationParameter[] => {
|
|
26
|
+
const preconfigured: IReflectHttpOperationParameter.IPreconfigured[] =
|
|
27
|
+
analyzePreconfigured(ctx);
|
|
28
|
+
const imports: IReflectTypeImport[] = [];
|
|
29
|
+
const errors: IReflectOperationError[] = [];
|
|
30
|
+
|
|
31
|
+
//----
|
|
32
|
+
// FIND CONTRADICTIONS
|
|
33
|
+
//----
|
|
34
|
+
// GET AND HEAD METHOD
|
|
35
|
+
const contradictErrors: string[] = [];
|
|
36
|
+
const contradict = (message: string) => {
|
|
37
|
+
contradictErrors.push(message);
|
|
38
|
+
};
|
|
39
|
+
if (
|
|
40
|
+
(ctx.httpMethod === "GET" || ctx.httpMethod === "HEAD") &&
|
|
41
|
+
preconfigured.some((x) => x.category === "body")
|
|
42
|
+
)
|
|
43
|
+
contradict(`@Body() is not allowed in the ${ctx.httpMethod} method.`);
|
|
44
|
+
|
|
45
|
+
// FIND DUPLICATED BODY
|
|
46
|
+
if (
|
|
47
|
+
preconfigured.filter(
|
|
48
|
+
(x) => x.category === "body" && x.field === undefined,
|
|
49
|
+
).length > 1
|
|
50
|
+
)
|
|
51
|
+
contradict(`Duplicated @Body() is not allowed.`);
|
|
52
|
+
if (
|
|
53
|
+
preconfigured.filter(
|
|
54
|
+
(x) => x.category === "query" && x.field === undefined,
|
|
55
|
+
).length > 1
|
|
56
|
+
)
|
|
57
|
+
contradict(`Duplicated @Query() without field name is not allowed.`);
|
|
58
|
+
if (
|
|
59
|
+
preconfigured.filter(
|
|
60
|
+
(x) => x.category === "headers" && x.field === undefined,
|
|
61
|
+
).length > 1
|
|
62
|
+
)
|
|
63
|
+
contradict(`Duplicated @Headers() without field name is not allowed.`);
|
|
64
|
+
|
|
65
|
+
// FIND DUPLICATED FIELDS
|
|
66
|
+
if (
|
|
67
|
+
isUnique(
|
|
68
|
+
preconfigured
|
|
69
|
+
.filter((x) => x.category === "param")
|
|
70
|
+
.map((x) => x.field)
|
|
71
|
+
.filter((field) => field !== undefined),
|
|
72
|
+
) === false
|
|
73
|
+
)
|
|
74
|
+
contradict(`Duplicated field names of path are not allowed.`);
|
|
75
|
+
if (
|
|
76
|
+
isUnique(
|
|
77
|
+
preconfigured
|
|
78
|
+
.filter((x) => x.category === "query")
|
|
79
|
+
.map((x) => x.field)
|
|
80
|
+
.filter((field) => field !== undefined),
|
|
81
|
+
) === false
|
|
82
|
+
)
|
|
83
|
+
contradict(`Duplicated field names of query are not allowed.`);
|
|
84
|
+
if (
|
|
85
|
+
isUnique(
|
|
86
|
+
preconfigured
|
|
87
|
+
.filter((x) => x.category === "headers")
|
|
88
|
+
.map((x) => x.field)
|
|
89
|
+
.filter((field) => field !== undefined),
|
|
90
|
+
) === false
|
|
91
|
+
)
|
|
92
|
+
contradict(`Duplicated field names of headers are not allowed.`);
|
|
93
|
+
if (contradictErrors.length)
|
|
94
|
+
errors.push({
|
|
95
|
+
file: ctx.controller.file,
|
|
96
|
+
class: ctx.controller.class.name,
|
|
97
|
+
function: ctx.functionName,
|
|
98
|
+
from: "",
|
|
99
|
+
contents: contradictErrors,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
//----
|
|
103
|
+
// COMPOSE PARAMETERS
|
|
104
|
+
//----
|
|
105
|
+
const parameters: IReflectHttpOperationParameter[] = preconfigured
|
|
106
|
+
.map((p): IReflectHttpOperationParameter | null => {
|
|
107
|
+
// METADATA INFO
|
|
108
|
+
const pErrorContents: Array<string | IOperationMetadata.IError> = [];
|
|
109
|
+
const matched: IOperationMetadata.IParameter | undefined =
|
|
110
|
+
ctx.metadata.parameters.find((x) => x.index === p.index);
|
|
111
|
+
const report = () => {
|
|
112
|
+
errors.push({
|
|
113
|
+
file: ctx.controller.file,
|
|
114
|
+
class: ctx.controller.class.name,
|
|
115
|
+
function: ctx.functionName,
|
|
116
|
+
from: `parameter ${matched ? JSON.stringify(matched.name) : `of ${p.index} th`}`,
|
|
117
|
+
contents: pErrorContents,
|
|
118
|
+
});
|
|
119
|
+
return null;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// VALIDATE TYPE
|
|
123
|
+
if (matched === undefined)
|
|
124
|
+
pErrorContents.push(`Unable to find parameter type.`);
|
|
125
|
+
else if (matched.type === null)
|
|
126
|
+
pErrorContents.push(`Failed to get the type info.`);
|
|
127
|
+
|
|
128
|
+
// CONSIDER KIND
|
|
129
|
+
const schema: IOperationMetadata.ISchema | null = (() => {
|
|
130
|
+
if (matched === undefined) return null;
|
|
131
|
+
const result =
|
|
132
|
+
p.category === "body" &&
|
|
133
|
+
(p.contentType === "application/json" || p.encrypted === true)
|
|
134
|
+
? matched.primitive
|
|
135
|
+
: matched.resolved;
|
|
136
|
+
return result.success ? result.data : null;
|
|
137
|
+
})();
|
|
138
|
+
if (p.category === "body" && p.field !== undefined)
|
|
139
|
+
pErrorContents.push(`@Body() must not have a field name.`);
|
|
140
|
+
else if (p.category === "param" && p.field === undefined)
|
|
141
|
+
pErrorContents.push(`@Param() must have a field name.`);
|
|
142
|
+
|
|
143
|
+
if (pErrorContents.length) return report();
|
|
144
|
+
else if (
|
|
145
|
+
matched === undefined ||
|
|
146
|
+
matched.type === null ||
|
|
147
|
+
schema === null
|
|
148
|
+
)
|
|
149
|
+
return null; // unreachable
|
|
150
|
+
|
|
151
|
+
// COMPOSITION
|
|
152
|
+
imports.push(...matched.imports);
|
|
153
|
+
if (p.category === "param")
|
|
154
|
+
return {
|
|
155
|
+
category: p.category,
|
|
156
|
+
index: p.index,
|
|
157
|
+
field: p.field!,
|
|
158
|
+
name: matched.name,
|
|
159
|
+
type: matched.type,
|
|
160
|
+
validate: HttpParameterProgrammer.validate,
|
|
161
|
+
description: matched.description,
|
|
162
|
+
jsDocTags: matched.jsDocTags,
|
|
163
|
+
...schema,
|
|
164
|
+
};
|
|
165
|
+
else if (p.category === "query" || p.category === "headers")
|
|
166
|
+
return {
|
|
167
|
+
category: p.category,
|
|
168
|
+
index: p.index,
|
|
169
|
+
field: p.field ?? null,
|
|
170
|
+
name: matched.name,
|
|
171
|
+
type: matched.type,
|
|
172
|
+
validate:
|
|
173
|
+
p.category === "query"
|
|
174
|
+
? HttpQueryProgrammer.validate
|
|
175
|
+
: HttpHeadersProgrammer.validate,
|
|
176
|
+
description: matched.description,
|
|
177
|
+
jsDocTags: matched.jsDocTags,
|
|
178
|
+
...schema,
|
|
179
|
+
};
|
|
180
|
+
else if (p.category === "body")
|
|
181
|
+
return {
|
|
182
|
+
category: p.category,
|
|
183
|
+
index: p.index,
|
|
184
|
+
encrypted: !!p.encrypted,
|
|
185
|
+
contentType: p.contentType,
|
|
186
|
+
name: matched.name,
|
|
187
|
+
type: matched.type,
|
|
188
|
+
validate:
|
|
189
|
+
p.contentType === "application/json" || p.encrypted === true
|
|
190
|
+
? JsonMetadataFactory.validate
|
|
191
|
+
: p.contentType === "application/x-www-form-urlencoded"
|
|
192
|
+
? HttpQueryProgrammer.validate
|
|
193
|
+
: p.contentType === "multipart/form-data"
|
|
194
|
+
? HttpFormDataProgrammer.validate
|
|
195
|
+
: TextPlainValidator.validate,
|
|
196
|
+
description: matched.description,
|
|
197
|
+
jsDocTags: matched.jsDocTags,
|
|
198
|
+
...schema,
|
|
199
|
+
};
|
|
200
|
+
else {
|
|
201
|
+
pErrorContents.push(`Unknown kind of the parameter.`);
|
|
202
|
+
return report();
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
.filter((x): x is IReflectHttpOperationParameter => x !== null);
|
|
206
|
+
|
|
207
|
+
if (errors.length) ctx.errors.push(...errors);
|
|
208
|
+
return parameters;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const analyzePreconfigured = (
|
|
212
|
+
props: IContext,
|
|
213
|
+
): IReflectHttpOperationParameter.IPreconfigured[] => {
|
|
214
|
+
const dict: NestParameters | undefined = Reflect.getMetadata(
|
|
215
|
+
ROUTE_ARGS_METADATA,
|
|
216
|
+
props.controller.class,
|
|
217
|
+
props.functionName,
|
|
218
|
+
);
|
|
219
|
+
if (dict === undefined) return [];
|
|
220
|
+
return Object.entries(dict)
|
|
221
|
+
.map(([key, param]) => analyzeHttpParameter(key, param))
|
|
222
|
+
.filter(
|
|
223
|
+
(x): x is IReflectHttpOperationParameter.IPreconfigured => x !== null,
|
|
224
|
+
)
|
|
225
|
+
.sort((x, y) => x.index - y.index);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const analyzeHttpParameter = (
|
|
229
|
+
key: string,
|
|
230
|
+
param: INestParam,
|
|
231
|
+
): IReflectHttpOperationParameter.IPreconfigured | null => {
|
|
232
|
+
const symbol: string = key.split(":")[0];
|
|
233
|
+
if (symbol.indexOf("__custom") !== -1) return analyzeCustomParameter(param);
|
|
234
|
+
|
|
235
|
+
const category:
|
|
236
|
+
| IReflectHttpOperationParameter.IPreconfigured["category"]
|
|
237
|
+
| null = getNestParamType(Number(symbol[0]) as RouteParamtypes);
|
|
238
|
+
if (category === null) return null;
|
|
239
|
+
if (category === "body")
|
|
240
|
+
return {
|
|
241
|
+
category: "body",
|
|
242
|
+
index: param.index,
|
|
243
|
+
field: param.data,
|
|
244
|
+
contentType: "application/json",
|
|
245
|
+
};
|
|
246
|
+
else
|
|
247
|
+
return {
|
|
248
|
+
category,
|
|
249
|
+
index: param.index,
|
|
250
|
+
field: param.data,
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const analyzeCustomParameter = (
|
|
255
|
+
param: INestParam,
|
|
256
|
+
): IReflectHttpOperationParameter.IPreconfigured | null => {
|
|
257
|
+
if (param.factory === undefined) return null;
|
|
258
|
+
else if (
|
|
259
|
+
param.factory.name === "EncryptedBody" ||
|
|
260
|
+
param.factory.name === "PlainBody" ||
|
|
261
|
+
param.factory.name === "TypedQueryBody" ||
|
|
262
|
+
param.factory.name === "TypedBody" ||
|
|
263
|
+
param.factory.name === "TypedFormDataBody"
|
|
264
|
+
)
|
|
265
|
+
return {
|
|
266
|
+
category: "body",
|
|
267
|
+
index: param.index,
|
|
268
|
+
encrypted: param.factory.name === "EncryptedBody",
|
|
269
|
+
contentType:
|
|
270
|
+
param.factory.name === "PlainBody" ||
|
|
271
|
+
param.factory.name === "EncryptedBody"
|
|
272
|
+
? "text/plain"
|
|
273
|
+
: param.factory.name === "TypedQueryBody"
|
|
274
|
+
? "application/x-www-form-urlencoded"
|
|
275
|
+
: param.factory.name === "TypedFormDataBody"
|
|
276
|
+
? "multipart/form-data"
|
|
277
|
+
: "application/json",
|
|
278
|
+
};
|
|
279
|
+
else if (param.factory.name === "TypedHeaders")
|
|
280
|
+
return {
|
|
281
|
+
category: "headers",
|
|
282
|
+
index: param.index,
|
|
283
|
+
field: param.data,
|
|
284
|
+
};
|
|
285
|
+
else if (param.factory.name === "TypedParam")
|
|
286
|
+
return {
|
|
287
|
+
category: "param",
|
|
288
|
+
index: param.index,
|
|
289
|
+
field: param.data,
|
|
290
|
+
};
|
|
291
|
+
else if (param.factory.name === "TypedQuery")
|
|
292
|
+
return {
|
|
293
|
+
category: "query",
|
|
294
|
+
index: param.index,
|
|
295
|
+
field: undefined,
|
|
296
|
+
};
|
|
297
|
+
else return null;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const isUnique = (values: string[]) => new Set(values).size === values.length;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
type NestParameters = {
|
|
304
|
+
[key: string]: INestParam;
|
|
305
|
+
};
|
|
306
|
+
interface INestParam {
|
|
307
|
+
name: string;
|
|
308
|
+
index: number;
|
|
309
|
+
factory?: (...args: any) => any;
|
|
310
|
+
data: string | undefined;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const getNestParamType = (value: RouteParamtypes) => {
|
|
314
|
+
if (value === RouteParamtypes.BODY) return "body";
|
|
315
|
+
else if (value === RouteParamtypes.HEADERS) return "headers";
|
|
316
|
+
else if (value === RouteParamtypes.QUERY) return "query";
|
|
317
|
+
else if (value === RouteParamtypes.PARAM) return "param";
|
|
318
|
+
return null;
|
|
319
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HEADERS_METADATA,
|
|
3
|
+
HTTP_CODE_METADATA,
|
|
4
|
+
INTERCEPTORS_METADATA,
|
|
5
|
+
} from "@nestjs/common/constants";
|
|
6
|
+
import typia from "typia";
|
|
7
|
+
import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
|
|
8
|
+
import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
|
|
9
|
+
|
|
10
|
+
import { IReflectController } from "../structures/IReflectController";
|
|
11
|
+
import { IReflectHttpOperationSuccess } from "../structures/IReflectHttpOperationSuccess";
|
|
12
|
+
import { IReflectOperationError } from "../structures/IReflectOperationError";
|
|
13
|
+
import { IOperationMetadata } from "../transformers/IOperationMetadata";
|
|
14
|
+
import { TextPlainValidator } from "../transformers/TextPlainValidator";
|
|
15
|
+
|
|
16
|
+
export namespace ReflectHttpOperationResponseAnalyzer {
|
|
17
|
+
export interface IContext {
|
|
18
|
+
controller: IReflectController;
|
|
19
|
+
function: Function;
|
|
20
|
+
functionName: string;
|
|
21
|
+
httpMethod: string;
|
|
22
|
+
metadata: IOperationMetadata;
|
|
23
|
+
errors: IReflectOperationError[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const analyze = (
|
|
27
|
+
ctx: IContext,
|
|
28
|
+
): IReflectHttpOperationSuccess | null => {
|
|
29
|
+
const errors: Array<string | IOperationMetadata.IError> = [];
|
|
30
|
+
const report = () => {
|
|
31
|
+
ctx.errors.push({
|
|
32
|
+
file: ctx.controller.file,
|
|
33
|
+
class: ctx.controller.class.name,
|
|
34
|
+
function: ctx.functionName,
|
|
35
|
+
from: "return",
|
|
36
|
+
contents: errors,
|
|
37
|
+
});
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const encrypted: boolean = hasInterceptor({
|
|
42
|
+
name: "EncryptedRouteInterceptor",
|
|
43
|
+
function: ctx.function,
|
|
44
|
+
});
|
|
45
|
+
const contentType: string | null = encrypted
|
|
46
|
+
? "text/plain"
|
|
47
|
+
: hasInterceptor({
|
|
48
|
+
name: "TypedQueryRouteInterceptor",
|
|
49
|
+
function: ctx.function,
|
|
50
|
+
})
|
|
51
|
+
? "application/x-www-form-urlencoded"
|
|
52
|
+
: Reflect.getMetadata(HEADERS_METADATA, ctx.function)?.find(
|
|
53
|
+
(h: Record<string, string>) =>
|
|
54
|
+
typeof h?.name === "string" &&
|
|
55
|
+
typeof h?.value === "string" &&
|
|
56
|
+
h.name.toLowerCase() === "content-type",
|
|
57
|
+
)?.value ?? (ctx.httpMethod === "HEAD" ? null : "application/json");
|
|
58
|
+
|
|
59
|
+
const schema =
|
|
60
|
+
contentType === "application/json"
|
|
61
|
+
? ctx.metadata.success.primitive
|
|
62
|
+
: ctx.metadata.success.resolved;
|
|
63
|
+
if (schema.success === false) errors.push(...schema.errors);
|
|
64
|
+
if (ctx.httpMethod === "HEAD" && contentType !== null)
|
|
65
|
+
errors.push(`HEAD method must not have a content type.`);
|
|
66
|
+
if (
|
|
67
|
+
typia.is<IReflectHttpOperationSuccess["contentType"]>(contentType) ===
|
|
68
|
+
false
|
|
69
|
+
)
|
|
70
|
+
errors.push(
|
|
71
|
+
`@nestia/sdk does not support ${JSON.stringify(contentType)} content type.`,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (errors.length) return report();
|
|
75
|
+
else if (
|
|
76
|
+
ctx.metadata.success.type === null ||
|
|
77
|
+
schema.success === false ||
|
|
78
|
+
!typia.is<IReflectHttpOperationSuccess["contentType"]>(contentType)
|
|
79
|
+
)
|
|
80
|
+
return null;
|
|
81
|
+
return {
|
|
82
|
+
contentType: contentType,
|
|
83
|
+
encrypted,
|
|
84
|
+
status:
|
|
85
|
+
getStatus(ctx.function) ?? (ctx.httpMethod === "POST" ? 201 : 200),
|
|
86
|
+
type: ctx.metadata.success.type,
|
|
87
|
+
...schema.data,
|
|
88
|
+
validate:
|
|
89
|
+
contentType === "application/json" || encrypted === true
|
|
90
|
+
? JsonMetadataFactory.validate
|
|
91
|
+
: contentType === "application/x-www-form-urlencoded"
|
|
92
|
+
? HttpQueryProgrammer.validate
|
|
93
|
+
: contentType === "text/plain"
|
|
94
|
+
? TextPlainValidator.validate
|
|
95
|
+
: (meta) =>
|
|
96
|
+
meta.size()
|
|
97
|
+
? ["HEAD method must not have any return value."]
|
|
98
|
+
: [],
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const getStatus = (func: Function): number | null => {
|
|
103
|
+
const text = Reflect.getMetadata(HTTP_CODE_METADATA, func);
|
|
104
|
+
if (text === undefined) return null;
|
|
105
|
+
const value: number = Number(text);
|
|
106
|
+
return isNaN(value) ? null : value;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const hasInterceptor = (props: {
|
|
110
|
+
name: string;
|
|
111
|
+
function: Function;
|
|
112
|
+
}): boolean => {
|
|
113
|
+
const meta = Reflect.getMetadata(INTERCEPTORS_METADATA, props.function);
|
|
114
|
+
if (Array.isArray(meta) === false) return false;
|
|
115
|
+
return meta.some((elem) => elem?.constructor?.name === props.name);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -2,27 +2,10 @@ import { VERSION_NEUTRAL } from "@nestjs/common";
|
|
|
2
2
|
import { PATH_METADATA, VERSION_METADATA } from "@nestjs/common/constants";
|
|
3
3
|
import { VersionValue } from "@nestjs/common/interfaces";
|
|
4
4
|
|
|
5
|
-
import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
|
|
6
5
|
import { SecurityAnalyzer } from "./SecurityAnalyzer";
|
|
7
6
|
|
|
8
7
|
export namespace ReflectMetadataAnalyzer {
|
|
9
|
-
export const
|
|
10
|
-
value: any,
|
|
11
|
-
): Record<
|
|
12
|
-
number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
13
|
-
IReflectHttpOperation.IException
|
|
14
|
-
> => {
|
|
15
|
-
const entire: IReflectHttpOperation.IException[] | undefined =
|
|
16
|
-
Reflect.getMetadata("nestia/TypedException", value);
|
|
17
|
-
return Object.fromEntries(
|
|
18
|
-
(entire ?? []).map((exp) => [exp.status, exp]),
|
|
19
|
-
) as Record<
|
|
20
|
-
number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
21
|
-
IReflectHttpOperation.IException
|
|
22
|
-
>;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const paths = (target: any): string[] => {
|
|
8
|
+
export const paths = (target: Function): string[] => {
|
|
26
9
|
const value: string | string[] = Reflect.getMetadata(PATH_METADATA, target);
|
|
27
10
|
if (typeof value === "string") return [value];
|
|
28
11
|
else if (value.length === 0) return [""];
|