@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,29 +1,31 @@
|
|
|
1
|
-
import transform from "@nestia/core/lib/transform";
|
|
2
1
|
import fs from "fs";
|
|
3
2
|
import path from "path";
|
|
4
|
-
import
|
|
3
|
+
import { HashSet, Pair, TreeMap } from "tstl";
|
|
4
|
+
import { IMetadataDictionary } from "typia/lib/schemas/metadata/IMetadataDictionary";
|
|
5
5
|
|
|
6
6
|
import { INestiaConfig } from "./INestiaConfig";
|
|
7
7
|
import { AccessorAnalyzer } from "./analyses/AccessorAnalyzer";
|
|
8
8
|
import { ConfigAnalyzer } from "./analyses/ConfigAnalyzer";
|
|
9
|
+
import { PathAnalyzer } from "./analyses/PathAnalyzer";
|
|
9
10
|
import { ReflectControllerAnalyzer } from "./analyses/ReflectControllerAnalyzer";
|
|
10
|
-
import {
|
|
11
|
+
import { TypedHttpRouteAnalyzer } from "./analyses/TypedHttpRouteAnalyzer";
|
|
12
|
+
import { TypedWebSocketRouteAnalyzer } from "./analyses/TypedWebSocketRouteAnalyzer";
|
|
11
13
|
import { E2eGenerator } from "./generates/E2eGenerator";
|
|
12
14
|
import { OpenAiGenerator } from "./generates/OpenAiGenerator";
|
|
13
15
|
import { SdkGenerator } from "./generates/SdkGenerator";
|
|
14
16
|
import { SwaggerGenerator } from "./generates/SwaggerGenerator";
|
|
15
|
-
import { IErrorReport } from "./structures/IErrorReport";
|
|
16
17
|
import { INestiaProject } from "./structures/INestiaProject";
|
|
17
18
|
import { IReflectController } from "./structures/IReflectController";
|
|
19
|
+
import { IReflectOperationError } from "./structures/IReflectOperationError";
|
|
20
|
+
import { ITypedApplication } from "./structures/ITypedApplication";
|
|
18
21
|
import { ITypedHttpRoute } from "./structures/ITypedHttpRoute";
|
|
19
22
|
import { ITypedWebSocketRoute } from "./structures/ITypedWebSocketRoute";
|
|
20
|
-
import {
|
|
23
|
+
import { IOperationMetadata } from "./transformers/IOperationMetadata";
|
|
24
|
+
import { StringUtil } from "./utils/StringUtil";
|
|
25
|
+
import { VersioningStrategy } from "./utils/VersioningStrategy";
|
|
21
26
|
|
|
22
27
|
export class NestiaSdkApplication {
|
|
23
|
-
public constructor(
|
|
24
|
-
private readonly config: INestiaConfig,
|
|
25
|
-
private readonly compilerOptions: ts.CompilerOptions,
|
|
26
|
-
) {}
|
|
28
|
+
public constructor(private readonly config: INestiaConfig) {}
|
|
27
29
|
|
|
28
30
|
public async e2e(): Promise<void> {
|
|
29
31
|
if (!this.config.output)
|
|
@@ -49,11 +51,11 @@ export class NestiaSdkApplication {
|
|
|
49
51
|
await validate("e2e")(this.config.e2e);
|
|
50
52
|
|
|
51
53
|
print_title("Nestia E2E Generator");
|
|
52
|
-
await this.generate(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
await this.generate({
|
|
55
|
+
generate: async (app) => {
|
|
56
|
+
await SdkGenerator.generate(app);
|
|
57
|
+
await E2eGenerator.generate(app);
|
|
58
|
+
},
|
|
57
59
|
});
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -71,7 +73,10 @@ export class NestiaSdkApplication {
|
|
|
71
73
|
);
|
|
72
74
|
|
|
73
75
|
print_title("Nestia SDK Generator");
|
|
74
|
-
await this.generate(
|
|
76
|
+
await this.generate({
|
|
77
|
+
generate: SdkGenerator.generate,
|
|
78
|
+
validate: SdkGenerator.validate,
|
|
79
|
+
});
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
public async swagger(): Promise<void> {
|
|
@@ -91,7 +96,9 @@ export class NestiaSdkApplication {
|
|
|
91
96
|
);
|
|
92
97
|
|
|
93
98
|
print_title("Nestia Swagger Generator");
|
|
94
|
-
await this.generate(
|
|
99
|
+
await this.generate({
|
|
100
|
+
generate: SwaggerGenerator.generate,
|
|
101
|
+
});
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
public async openai(): Promise<void> {
|
|
@@ -111,21 +118,19 @@ export class NestiaSdkApplication {
|
|
|
111
118
|
);
|
|
112
119
|
|
|
113
120
|
print_title("Nestia OpenAI Function Calling Schema Generator");
|
|
114
|
-
await this.generate(
|
|
121
|
+
await this.generate({
|
|
122
|
+
generate: OpenAiGenerator.generate,
|
|
123
|
+
});
|
|
115
124
|
}
|
|
116
125
|
|
|
117
|
-
private async generate(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
routes: Array<ITypedHttpRoute | ITypedWebSocketRoute>,
|
|
122
|
-
) => Promise<void>,
|
|
123
|
-
): Promise<void> {
|
|
126
|
+
private async generate(props: {
|
|
127
|
+
generate: (app: ITypedApplication) => Promise<void>;
|
|
128
|
+
validate?: (app: ITypedApplication) => IReflectOperationError[];
|
|
129
|
+
}): Promise<void> {
|
|
124
130
|
//----
|
|
125
131
|
// ANALYZE REFLECTS
|
|
126
132
|
//----
|
|
127
133
|
const unique: WeakSet<any> = new WeakSet();
|
|
128
|
-
const controllers: IReflectController[] = [];
|
|
129
134
|
const project: INestiaProject = {
|
|
130
135
|
config: this.config,
|
|
131
136
|
input: await ConfigAnalyzer.input(this.config),
|
|
@@ -135,28 +140,36 @@ export class NestiaSdkApplication {
|
|
|
135
140
|
};
|
|
136
141
|
|
|
137
142
|
console.log("Analyzing reflections");
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
const controllers: IReflectController[] = project.input.controllers
|
|
144
|
+
.map((c) =>
|
|
145
|
+
ReflectControllerAnalyzer.analyze({ project, controller: c, unique }),
|
|
146
|
+
)
|
|
147
|
+
.filter((c): c is IReflectController => c !== null);
|
|
148
|
+
|
|
149
|
+
if (project.warnings.length)
|
|
150
|
+
report({
|
|
151
|
+
type: "warning",
|
|
152
|
+
errors: project.warnings,
|
|
153
|
+
});
|
|
154
|
+
if (project.errors.length)
|
|
155
|
+
return report({
|
|
156
|
+
type: "error",
|
|
157
|
+
errors: project.errors,
|
|
158
|
+
});
|
|
149
159
|
|
|
150
160
|
const agg: number = (() => {
|
|
151
|
-
const set:
|
|
152
|
-
for (const
|
|
153
|
-
for (const
|
|
154
|
-
for (const
|
|
155
|
-
for (const
|
|
156
|
-
set.
|
|
157
|
-
|
|
161
|
+
const set: HashSet<Pair<string, string>> = new HashSet();
|
|
162
|
+
for (const controller of controllers)
|
|
163
|
+
for (const controllerPath of controller.paths)
|
|
164
|
+
for (const operation of controller.operations)
|
|
165
|
+
for (const operationPath of operation.paths)
|
|
166
|
+
set.insert(
|
|
167
|
+
new Pair(
|
|
168
|
+
`${controllerPath}/${operationPath}`,
|
|
169
|
+
operation.protocol === "http" ? operation.method : "",
|
|
170
|
+
),
|
|
158
171
|
);
|
|
159
|
-
return set.size;
|
|
172
|
+
return set.size();
|
|
160
173
|
})();
|
|
161
174
|
|
|
162
175
|
console.log(` - controllers: #${controllers.length}`);
|
|
@@ -174,82 +187,64 @@ export class NestiaSdkApplication {
|
|
|
174
187
|
//----
|
|
175
188
|
// ANALYZE TYPESCRIPT CODE
|
|
176
189
|
//----
|
|
177
|
-
console.log("Analyzing
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
})()
|
|
236
|
-
: [0, 0];
|
|
237
|
-
console.error(
|
|
238
|
-
`${file}:${line}:${pos} - ${category} TS${diag.code}: ${diag.messageText}`,
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
if (diagnostics.length) process.exit(-1);
|
|
242
|
-
|
|
243
|
-
// REPORT ERRORS
|
|
244
|
-
if (project.errors.length) {
|
|
245
|
-
report_errors("error")(project.errors);
|
|
246
|
-
process.exit(-1);
|
|
247
|
-
}
|
|
248
|
-
if (project.warnings.length) report_errors("warning")(project.warnings);
|
|
249
|
-
|
|
250
|
-
// DO GENERATE
|
|
251
|
-
AccessorAnalyzer.analyze(routeList);
|
|
252
|
-
await archiver(project)(routeList);
|
|
190
|
+
console.log("Analyzing soure codes");
|
|
191
|
+
|
|
192
|
+
// METADATA COMPONENTS
|
|
193
|
+
const collection: IMetadataDictionary =
|
|
194
|
+
TypedHttpRouteAnalyzer.dictionary(controllers);
|
|
195
|
+
|
|
196
|
+
// CONVERT TO TYPED OPERATIONS
|
|
197
|
+
const globalPrefix: string = project.input.globalPrefix?.prefix ?? "";
|
|
198
|
+
const routes: Array<ITypedHttpRoute | ITypedWebSocketRoute> = [];
|
|
199
|
+
for (const c of controllers)
|
|
200
|
+
for (const o of c.operations) {
|
|
201
|
+
const pathList: Set<string> = new Set();
|
|
202
|
+
const versions: string[] = VersioningStrategy.merge(project)([
|
|
203
|
+
...(c.versions ?? []),
|
|
204
|
+
...(o.versions ?? []),
|
|
205
|
+
]);
|
|
206
|
+
for (const v of versions)
|
|
207
|
+
for (const prefix of wrapPaths(c.prefixes))
|
|
208
|
+
for (const cPath of wrapPaths(c.paths))
|
|
209
|
+
for (const filePath of wrapPaths(o.paths))
|
|
210
|
+
pathList.add(
|
|
211
|
+
PathAnalyzer.join(globalPrefix, v, prefix, cPath, filePath),
|
|
212
|
+
);
|
|
213
|
+
if (o.protocol === "http")
|
|
214
|
+
routes.push(
|
|
215
|
+
...TypedHttpRouteAnalyzer.analyze({
|
|
216
|
+
controller: c,
|
|
217
|
+
errors: project.errors,
|
|
218
|
+
dictionary: collection,
|
|
219
|
+
operation: o,
|
|
220
|
+
paths: Array.from(pathList),
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
223
|
+
else if (o.protocol === "websocket")
|
|
224
|
+
routes.push(
|
|
225
|
+
...TypedWebSocketRouteAnalyzer.analyze({
|
|
226
|
+
controller: c,
|
|
227
|
+
operation: o,
|
|
228
|
+
paths: Array.from(pathList),
|
|
229
|
+
}),
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
AccessorAnalyzer.analyze(routes);
|
|
233
|
+
|
|
234
|
+
if (props.validate !== undefined)
|
|
235
|
+
props.validate({
|
|
236
|
+
project,
|
|
237
|
+
routes,
|
|
238
|
+
});
|
|
239
|
+
if (project.errors.length)
|
|
240
|
+
return report({
|
|
241
|
+
type: "error",
|
|
242
|
+
errors: project.errors,
|
|
243
|
+
});
|
|
244
|
+
await props.generate({
|
|
245
|
+
project,
|
|
246
|
+
routes,
|
|
247
|
+
});
|
|
253
248
|
}
|
|
254
249
|
}
|
|
255
250
|
|
|
@@ -275,44 +270,62 @@ const print_title = (str: string): void => {
|
|
|
275
270
|
// return true;
|
|
276
271
|
// };
|
|
277
272
|
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
273
|
+
const report = (props: {
|
|
274
|
+
type: "error" | "warning";
|
|
275
|
+
errors: IReflectOperationError[];
|
|
276
|
+
}): void => {
|
|
277
|
+
const map: TreeMap<
|
|
278
|
+
IReflectOperationError.Key,
|
|
279
|
+
Array<string | IOperationMetadata.IError>
|
|
280
|
+
> = new TreeMap();
|
|
281
|
+
for (const e of props.errors)
|
|
282
|
+
map.take(new IReflectOperationError.Key(e), () => []).push(...e.contents);
|
|
283
|
+
|
|
284
|
+
console.log("");
|
|
285
|
+
print_title(`Nestia ${StringUtil.capitalize(props.type)} Report`);
|
|
286
|
+
|
|
287
|
+
for (const {
|
|
288
|
+
first: { error },
|
|
289
|
+
second: contents,
|
|
290
|
+
} of map) {
|
|
291
|
+
if (error.contents.length === 0) continue;
|
|
292
|
+
const location: string = path.relative(process.cwd(), error.file);
|
|
293
|
+
const message: string = [
|
|
294
|
+
`${location} - `,
|
|
295
|
+
error.class,
|
|
296
|
+
...(error.function !== null ? [`.${error.function}()`] : [""]),
|
|
297
|
+
...(error.from !== null ? [` from ${error.from}`] : [""]),
|
|
298
|
+
":\n",
|
|
299
|
+
contents
|
|
300
|
+
.map((c) => {
|
|
301
|
+
if (typeof c === "string") return ` - ${c}`;
|
|
302
|
+
else
|
|
303
|
+
return [
|
|
304
|
+
c.accessor
|
|
305
|
+
? ` - ${c.name}: `
|
|
306
|
+
: ` - ${c.name} (${c.accessor}): `,
|
|
307
|
+
...c.messages.map((msg) => ` - ${msg}`),
|
|
308
|
+
].join("\n");
|
|
309
|
+
})
|
|
310
|
+
.join("\n"),
|
|
311
|
+
].join("");
|
|
312
|
+
console.log(message);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// for (const [file, cMap] of map) {
|
|
316
|
+
// for (const [controller, fMap] of cMap)
|
|
317
|
+
// for (const [func, messages] of fMap) {
|
|
318
|
+
// const location: string = path.relative(process.cwd(), file);
|
|
319
|
+
// console.log(
|
|
320
|
+
// `${location} - ${
|
|
321
|
+
// func !== null ? `${controller}.${func}()` : controller
|
|
322
|
+
// }`,
|
|
323
|
+
// );
|
|
324
|
+
// for (const msg of messages) console.log(` - ${msg}`);
|
|
325
|
+
// console.log("");
|
|
326
|
+
// }
|
|
327
|
+
// }
|
|
318
328
|
};
|
|
329
|
+
|
|
330
|
+
const wrapPaths = (paths: string[]): string[] =>
|
|
331
|
+
paths.length === 0 ? [""] : paths;
|
|
@@ -1,44 +1,43 @@
|
|
|
1
1
|
/// <reference path="../typings/get-function-location.d.ts" />
|
|
2
|
+
import { DynamicModule } from "@nestia/core";
|
|
2
3
|
import { INestApplication, VersioningType } from "@nestjs/common";
|
|
3
4
|
import { MODULE_PATH } from "@nestjs/common/constants";
|
|
4
|
-
import { NestContainer } from "@nestjs/core";
|
|
5
|
+
import { NestContainer, NestFactory } from "@nestjs/core";
|
|
5
6
|
import { Module } from "@nestjs/core/injector/module";
|
|
6
|
-
import fs from "fs";
|
|
7
7
|
import getFunctionLocation from "get-function-location";
|
|
8
|
-
import
|
|
9
|
-
import { HashMap, Pair, Singleton } from "tstl";
|
|
8
|
+
import { HashMap } from "tstl";
|
|
10
9
|
|
|
11
10
|
import { INestiaConfig } from "../INestiaConfig";
|
|
12
|
-
import {
|
|
13
|
-
import { INormalizedInput } from "../structures/INormalizedInput";
|
|
14
|
-
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
11
|
+
import { INestiaSdkInput } from "../structures/INestiaSdkInput";
|
|
15
12
|
import { MapUtil } from "../utils/MapUtil";
|
|
16
|
-
import { SourceFinder } from "../utils/SourceFinder";
|
|
17
13
|
|
|
18
14
|
export namespace ConfigAnalyzer {
|
|
19
|
-
export const input = (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
15
|
+
export const input = async (
|
|
16
|
+
config: INestiaConfig,
|
|
17
|
+
): Promise<INestiaSdkInput> => {
|
|
18
|
+
return MapUtil.take(memory, config, async () => {
|
|
19
|
+
const app: INestApplication =
|
|
20
|
+
typeof config.input === "function"
|
|
21
|
+
? await config.input()
|
|
22
|
+
: await NestFactory.create(
|
|
23
|
+
await DynamicModule.mount(config.input, {}, true as any),
|
|
24
|
+
{
|
|
25
|
+
logger: false,
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
return analyze_application(app);
|
|
32
29
|
});
|
|
30
|
+
};
|
|
33
31
|
|
|
34
32
|
const analyze_application = async (
|
|
35
33
|
app: INestApplication,
|
|
36
|
-
): Promise<
|
|
37
|
-
const files: HashMap<Pair<Function, string>, Set<string>> = new HashMap();
|
|
34
|
+
): Promise<INestiaSdkInput> => {
|
|
38
35
|
const container: NestContainer = (app as any).container as NestContainer;
|
|
39
36
|
const modules: Module[] = [...container.getModules().values()].filter(
|
|
40
37
|
(m) => !!m.controllers.size,
|
|
41
38
|
);
|
|
39
|
+
const unique: HashMap<Function, Set<string>> = new HashMap();
|
|
40
|
+
|
|
42
41
|
for (const m of modules) {
|
|
43
42
|
const path: string =
|
|
44
43
|
Reflect.getMetadata(
|
|
@@ -47,29 +46,28 @@ export namespace ConfigAnalyzer {
|
|
|
47
46
|
) ??
|
|
48
47
|
Reflect.getMetadata(MODULE_PATH, m.metatype) ??
|
|
49
48
|
"";
|
|
50
|
-
for (const controller of [...m.controllers.keys()])
|
|
51
|
-
|
|
52
|
-
(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
for (const controller of [...m.controllers.keys()])
|
|
50
|
+
if (typeof controller === "function")
|
|
51
|
+
unique.take(controller, () => new Set()).add(path);
|
|
52
|
+
}
|
|
53
|
+
const controllers: INestiaSdkInput.IController[] = [];
|
|
54
|
+
for (const it of unique) {
|
|
55
|
+
const file: string | null =
|
|
56
|
+
(await getFunctionLocation(it.first))?.source ?? null;
|
|
57
|
+
if (file === null) continue;
|
|
58
|
+
const location: string = normalize_file(file);
|
|
59
|
+
if (location.length === 0) continue;
|
|
60
|
+
controllers.push({
|
|
61
|
+
class: it.first,
|
|
62
|
+
prefixes: Array.from(it.second),
|
|
63
|
+
location,
|
|
64
|
+
});
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
const versioning = (app as any).config?.versioningOptions;
|
|
67
68
|
return {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
file: decodeURIComponent(pair.first.second),
|
|
71
|
-
paths: [...pair.second.values()],
|
|
72
|
-
})),
|
|
69
|
+
application: app,
|
|
70
|
+
controllers,
|
|
73
71
|
globalPrefix:
|
|
74
72
|
typeof (app as any).config?.globalPrefix === "string"
|
|
75
73
|
? {
|
|
@@ -89,61 +87,15 @@ export namespace ConfigAnalyzer {
|
|
|
89
87
|
},
|
|
90
88
|
};
|
|
91
89
|
};
|
|
92
|
-
|
|
93
|
-
const normalize_file = (str: string) =>
|
|
94
|
-
str.substring(
|
|
95
|
-
str.startsWith("file:///")
|
|
96
|
-
? process.cwd()[0] === "/"
|
|
97
|
-
? 7
|
|
98
|
-
: 8
|
|
99
|
-
: str.startsWith("file://")
|
|
100
|
-
? 7
|
|
101
|
-
: 0,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const transform_input =
|
|
105
|
-
(config: INestiaConfig) =>
|
|
106
|
-
async (include: string[], exclude?: string[]) => ({
|
|
107
|
-
include: (
|
|
108
|
-
await SourceFinder.find({
|
|
109
|
-
include,
|
|
110
|
-
exclude,
|
|
111
|
-
filter: filter(config),
|
|
112
|
-
})
|
|
113
|
-
).map((file) => ({
|
|
114
|
-
paths: [""],
|
|
115
|
-
file,
|
|
116
|
-
})),
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const filter =
|
|
120
|
-
(config: INestiaConfig) =>
|
|
121
|
-
async (location: string): Promise<boolean> =>
|
|
122
|
-
location.endsWith(".ts") &&
|
|
123
|
-
!location.endsWith(".d.ts") &&
|
|
124
|
-
(config.output === undefined ||
|
|
125
|
-
(location.indexOf(path.join(config.output, "functional")) === -1 &&
|
|
126
|
-
(await (
|
|
127
|
-
await bundler.get(config.output)
|
|
128
|
-
)(location))) === false);
|
|
129
90
|
}
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return new Pair(relative, stats.isDirectory());
|
|
141
|
-
},
|
|
91
|
+
const memory = new Map<INestiaConfig, Promise<INestiaSdkInput>>();
|
|
92
|
+
const normalize_file = (str: string) =>
|
|
93
|
+
str.substring(
|
|
94
|
+
str.startsWith("file:///")
|
|
95
|
+
? process.cwd()[0] === "/"
|
|
96
|
+
? 7
|
|
97
|
+
: 8
|
|
98
|
+
: str.startsWith("file://")
|
|
99
|
+
? 7
|
|
100
|
+
: 0,
|
|
142
101
|
);
|
|
143
|
-
return async (file: string): Promise<boolean> => {
|
|
144
|
-
for (const it of tuples)
|
|
145
|
-
if (it.second === false && file === it.first) return true;
|
|
146
|
-
else if (it.second === true && file.indexOf(it.first) === 0) return true;
|
|
147
|
-
return false;
|
|
148
|
-
};
|
|
149
|
-
});
|