@nestia/sdk 3.10.0 → 3.11.0-dev.20240813
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 +34 -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 +18 -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
|
@@ -3,32 +3,31 @@ import path from "path";
|
|
|
3
3
|
|
|
4
4
|
import { ConfigAnalyzer } from "../analyses/ConfigAnalyzer";
|
|
5
5
|
import { INestiaProject } from "../structures/INestiaProject";
|
|
6
|
-
import {
|
|
6
|
+
import { ITypedApplication } from "../structures/ITypedApplication";
|
|
7
7
|
import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
|
|
8
8
|
|
|
9
9
|
export namespace E2eGenerator {
|
|
10
|
-
export const generate =
|
|
11
|
-
(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
api: path.resolve(project.config.output!),
|
|
10
|
+
export const generate = async (app: ITypedApplication): Promise<void> => {
|
|
11
|
+
console.log("Generating E2E Test Functions");
|
|
12
|
+
|
|
13
|
+
// PREPARE DIRECTORIES
|
|
14
|
+
const output: string = path.resolve(app.project.config.e2e!);
|
|
15
|
+
await mkdir(output);
|
|
16
|
+
await mkdir(path.join(output, "features"));
|
|
17
|
+
await mkdir(path.join(output, "features", "api"));
|
|
18
|
+
await mkdir(path.join(output, "features", "api", "automated"));
|
|
19
|
+
|
|
20
|
+
// GENERATE TEST INDEX FILE
|
|
21
|
+
await index(app.project)(path.join(app.project.config.e2e!, "index.ts"));
|
|
22
|
+
|
|
23
|
+
// GENERATE EACH TEST FILES
|
|
24
|
+
for (const route of app.routes)
|
|
25
|
+
if (route.protocol === "http")
|
|
26
|
+
await E2eFileProgrammer.generate(app.project)({
|
|
27
|
+
api: path.resolve(app.project.config.output!),
|
|
29
28
|
current: path.join(output, "features", "api", "automated"),
|
|
30
29
|
})(route);
|
|
31
|
-
|
|
30
|
+
};
|
|
32
31
|
|
|
33
32
|
const index =
|
|
34
33
|
(project: INestiaProject) =>
|
|
@@ -6,55 +6,54 @@ import {
|
|
|
6
6
|
import fs from "fs";
|
|
7
7
|
import path from "path";
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
|
|
11
|
-
import { ITypedWebSocketRoute } from "../structures/ITypedWebSocketRoute";
|
|
9
|
+
import { ITypedApplication } from "../structures/ITypedApplication";
|
|
12
10
|
import { SwaggerGenerator } from "./SwaggerGenerator";
|
|
13
11
|
|
|
14
12
|
export namespace OpenAiGenerator {
|
|
15
|
-
export const generate =
|
|
16
|
-
(
|
|
17
|
-
async (
|
|
18
|
-
routes: Array<ITypedHttpRoute | ITypedWebSocketRoute>,
|
|
19
|
-
): Promise<void> => {
|
|
20
|
-
console.log("Generating OpenAI Function Calling Document");
|
|
13
|
+
export const generate = async (app: ITypedApplication): Promise<void> => {
|
|
14
|
+
console.log("Generating OpenAI Function Calling Document");
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (fs.existsSync(directory) === false)
|
|
26
|
-
try {
|
|
27
|
-
await fs.promises.mkdir(directory);
|
|
28
|
-
} catch {}
|
|
29
|
-
if (fs.existsSync(directory) === false)
|
|
30
|
-
throw new Error(
|
|
31
|
-
`Error on NestiaApplication.openai(): failed to create output directory: ${directory}`,
|
|
32
|
-
);
|
|
16
|
+
const config = app.project.config.openai;
|
|
17
|
+
if (config === undefined)
|
|
18
|
+
throw new Error("OpenAI configuration is not defined");
|
|
33
19
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
})(routes);
|
|
44
|
-
const document: IOpenAiDocument = OpenAiComposer.document({
|
|
45
|
-
swagger,
|
|
46
|
-
options: config,
|
|
47
|
-
});
|
|
48
|
-
await fs.promises.writeFile(
|
|
49
|
-
location,
|
|
50
|
-
!config.beautify
|
|
51
|
-
? JSON.stringify(document)
|
|
52
|
-
: JSON.stringify(
|
|
53
|
-
document,
|
|
54
|
-
null,
|
|
55
|
-
typeof config.beautify === "number" ? config.beautify : 2,
|
|
56
|
-
),
|
|
57
|
-
"utf8",
|
|
20
|
+
const parsed: path.ParsedPath = path.parse(config.output);
|
|
21
|
+
const directory: string = path.dirname(parsed.dir);
|
|
22
|
+
if (fs.existsSync(directory) === false)
|
|
23
|
+
try {
|
|
24
|
+
await fs.promises.mkdir(directory);
|
|
25
|
+
} catch {}
|
|
26
|
+
if (fs.existsSync(directory) === false)
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Error on NestiaApplication.openai(): failed to create output directory: ${directory}`,
|
|
58
29
|
);
|
|
59
|
-
|
|
30
|
+
|
|
31
|
+
const location: string = !!parsed.ext
|
|
32
|
+
? path.resolve(config.output)
|
|
33
|
+
: path.join(path.resolve(config.output), "openai.json");
|
|
34
|
+
const swagger: OpenApi.IDocument = await SwaggerGenerator.compose({
|
|
35
|
+
config: app.project.config.swagger ?? { output: "" },
|
|
36
|
+
routes: app.routes.filter((route) => route.protocol === "http"),
|
|
37
|
+
document: {
|
|
38
|
+
openapi: "3.1.0",
|
|
39
|
+
components: {},
|
|
40
|
+
"x-samchon-emended": true,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const document: IOpenAiDocument = OpenAiComposer.document({
|
|
44
|
+
swagger,
|
|
45
|
+
options: config,
|
|
46
|
+
});
|
|
47
|
+
await fs.promises.writeFile(
|
|
48
|
+
location,
|
|
49
|
+
!config.beautify
|
|
50
|
+
? JSON.stringify(document)
|
|
51
|
+
: JSON.stringify(
|
|
52
|
+
document,
|
|
53
|
+
null,
|
|
54
|
+
typeof config.beautify === "number" ? config.beautify : 2,
|
|
55
|
+
),
|
|
56
|
+
"utf8",
|
|
57
|
+
);
|
|
58
|
+
};
|
|
60
59
|
}
|
|
@@ -1,148 +1,120 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import NodePath from "path";
|
|
3
|
-
import path from "path";
|
|
4
3
|
import { IPointer } from "tstl";
|
|
5
|
-
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
6
4
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { INestiaConfig } from "../INestiaConfig";
|
|
6
|
+
import { IReflectOperationError } from "../structures/IReflectOperationError";
|
|
7
|
+
import { IReflectType } from "../structures/IReflectType";
|
|
8
|
+
import { ITypedApplication } from "../structures/ITypedApplication";
|
|
9
9
|
import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
|
|
10
|
-
import {
|
|
11
|
-
import { CloneGenerator } from "./CloneGenerator";
|
|
12
|
-
import { SwaggerGenerator } from "./SwaggerGenerator";
|
|
10
|
+
// import { CloneGenerator } from "./CloneGenerator";
|
|
13
11
|
import { SdkDistributionComposer } from "./internal/SdkDistributionComposer";
|
|
14
12
|
import { SdkFileProgrammer } from "./internal/SdkFileProgrammer";
|
|
15
13
|
|
|
16
14
|
export namespace SdkGenerator {
|
|
17
|
-
export const generate =
|
|
18
|
-
(project
|
|
19
|
-
|
|
20
|
-
routes: Array<ITypedHttpRoute | ITypedWebSocketRoute>,
|
|
21
|
-
): Promise<void> => {
|
|
22
|
-
console.log("Generating SDK Library");
|
|
15
|
+
export const generate = async (app: ITypedApplication): Promise<void> => {
|
|
16
|
+
if (app.project.config.output === undefined)
|
|
17
|
+
throw new Error("Output directory is not defined.");
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
collection: new MetadataCollection({
|
|
30
|
-
replace: MetadataCollection.replace,
|
|
31
|
-
}),
|
|
32
|
-
lazyProperties: [],
|
|
33
|
-
lazySchemas: [],
|
|
34
|
-
errors,
|
|
35
|
-
swagger: await SwaggerGenerator.initialize(
|
|
36
|
-
project.config.swagger ?? { output: "" },
|
|
37
|
-
),
|
|
38
|
-
});
|
|
39
|
-
for (const r of routes)
|
|
40
|
-
if (r.protocol === "http") {
|
|
41
|
-
validate(r);
|
|
42
|
-
if (project.config.clone !== true) validateImplicity(project)(r);
|
|
43
|
-
}
|
|
44
|
-
if (errors.length) {
|
|
45
|
-
for (const e of errors)
|
|
46
|
-
console.error(
|
|
47
|
-
`${path.relative(process.cwd(), e.route.location)}:${
|
|
48
|
-
e.route.controller.name
|
|
49
|
-
}.${e.route.name}:${
|
|
50
|
-
e.from
|
|
51
|
-
} - error TS(@nestia/sdk): invalid type detected.\n\n` +
|
|
52
|
-
e.messages.map((m) => ` - ${m}`).join("\n"),
|
|
53
|
-
"\n\n",
|
|
54
|
-
);
|
|
55
|
-
throw new TypeError("Invalid type detected");
|
|
56
|
-
} else if (project.errors.length) {
|
|
57
|
-
for (const e of project.errors)
|
|
58
|
-
console.error(
|
|
59
|
-
`${path.relative(process.cwd(), e.file)}:${
|
|
60
|
-
e.controller
|
|
61
|
-
}.${e.function}: error TS(@nestia/sdk): ${e.message}`,
|
|
62
|
-
);
|
|
63
|
-
throw new TypeError("Invalid type detected");
|
|
64
|
-
}
|
|
19
|
+
// PREPARE NEW DIRECTORIES
|
|
20
|
+
console.log("Generating SDK Library");
|
|
21
|
+
try {
|
|
22
|
+
await fs.promises.mkdir(app.project.config.output);
|
|
23
|
+
} catch {}
|
|
65
24
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
25
|
+
// BUNDLING
|
|
26
|
+
const bundle: string[] = await fs.promises.readdir(BUNDLE_PATH);
|
|
27
|
+
for (const file of bundle) {
|
|
28
|
+
const current: string = `${BUNDLE_PATH}/${file}`;
|
|
29
|
+
const target: string = `${app.project.config.output}/${file}`;
|
|
30
|
+
const stats: fs.Stats = await fs.promises.stat(current);
|
|
70
31
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
else if (BUNDLE_CHANGES[file] !== undefined) {
|
|
83
|
-
const r: IPointer<string> = {
|
|
84
|
-
value: await fs.promises.readFile(target, "utf8"),
|
|
85
|
-
};
|
|
86
|
-
for (const [before, after] of BUNDLE_CHANGES[file])
|
|
87
|
-
r.value = r.value.replace(before, after);
|
|
88
|
-
await fs.promises.writeFile(target, r.value, "utf8");
|
|
89
|
-
}
|
|
32
|
+
if (stats.isFile() === true) {
|
|
33
|
+
const content: string = await fs.promises.readFile(current, "utf8");
|
|
34
|
+
if (fs.existsSync(target) === false)
|
|
35
|
+
await fs.promises.writeFile(target, content, "utf8");
|
|
36
|
+
else if (BUNDLE_CHANGES[file] !== undefined) {
|
|
37
|
+
const r: IPointer<string> = {
|
|
38
|
+
value: await fs.promises.readFile(target, "utf8"),
|
|
39
|
+
};
|
|
40
|
+
for (const [before, after] of BUNDLE_CHANGES[file])
|
|
41
|
+
r.value = r.value.replace(before, after);
|
|
42
|
+
await fs.promises.writeFile(target, r.value, "utf8");
|
|
90
43
|
}
|
|
91
44
|
}
|
|
45
|
+
}
|
|
92
46
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
await CloneGenerator.write(project)(
|
|
96
|
-
routes.filter((r) => r.protocol === "http") as ITypedHttpRoute[],
|
|
97
|
-
);
|
|
47
|
+
// // STRUCTURES
|
|
48
|
+
// if (app.project.config.clone === true) await CloneGenerator.write(app);
|
|
98
49
|
|
|
99
|
-
|
|
100
|
-
|
|
50
|
+
// FUNCTIONAL
|
|
51
|
+
await SdkFileProgrammer.generate(app);
|
|
101
52
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
53
|
+
// DISTRIBUTION
|
|
54
|
+
if (app.project.config.distribute !== undefined)
|
|
55
|
+
await SdkDistributionComposer.compose({
|
|
56
|
+
config: app.project.config,
|
|
57
|
+
websocket: app.routes.some((r) => r.protocol === "websocket"),
|
|
58
|
+
});
|
|
59
|
+
};
|
|
109
60
|
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (isImplicitType(
|
|
132
|
-
|
|
133
|
-
file: route.
|
|
134
|
-
|
|
135
|
-
function: route.name,
|
|
136
|
-
|
|
61
|
+
export const validate = (
|
|
62
|
+
app: ITypedApplication,
|
|
63
|
+
): IReflectOperationError[] => {
|
|
64
|
+
const errors: IReflectOperationError[] = [];
|
|
65
|
+
if (app.project.config.clone === true) return errors;
|
|
66
|
+
for (const route of app.routes)
|
|
67
|
+
if (route.protocol === "http")
|
|
68
|
+
validateImplicity({
|
|
69
|
+
config: app.project.config,
|
|
70
|
+
errors,
|
|
71
|
+
route,
|
|
72
|
+
});
|
|
73
|
+
return errors;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const validateImplicity = (props: {
|
|
77
|
+
config: INestiaConfig;
|
|
78
|
+
errors: IReflectOperationError[];
|
|
79
|
+
route: ITypedHttpRoute;
|
|
80
|
+
}): void => {
|
|
81
|
+
for (const p of props.route.parameters) {
|
|
82
|
+
if (isImplicitType(p.type))
|
|
83
|
+
props.errors.push({
|
|
84
|
+
file: props.route.controller.file,
|
|
85
|
+
class: props.route.controller.class.name,
|
|
86
|
+
function: props.route.name,
|
|
87
|
+
from: `parameter ${JSON.stringify(p.name)}`,
|
|
88
|
+
contents: [`implicit (unnamed) parameter type.`],
|
|
137
89
|
});
|
|
138
|
-
}
|
|
90
|
+
}
|
|
91
|
+
if (props.config.propagate === true)
|
|
92
|
+
for (const [key, value] of Object.entries(props.route.exceptions))
|
|
93
|
+
if (isImplicitType(value.type))
|
|
94
|
+
props.errors.push({
|
|
95
|
+
file: props.route.controller.file,
|
|
96
|
+
class: props.route.controller.class.name,
|
|
97
|
+
function: props.route.name,
|
|
98
|
+
from: `exception ${JSON.stringify(key)}`,
|
|
99
|
+
contents: [`implicit (unnamed) exception type.`],
|
|
100
|
+
});
|
|
101
|
+
if (isImplicitType(props.route.success.type))
|
|
102
|
+
props.errors.push({
|
|
103
|
+
file: props.route.controller.file,
|
|
104
|
+
class: props.route.controller.class.name,
|
|
105
|
+
function: props.route.name,
|
|
106
|
+
from: "success",
|
|
107
|
+
contents: [`implicit (unnamed) return type.`],
|
|
108
|
+
});
|
|
109
|
+
};
|
|
139
110
|
|
|
140
|
-
const isImplicitType = (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
111
|
+
const isImplicitType = (type: IReflectType): boolean =>
|
|
112
|
+
type.name === "__type" ||
|
|
113
|
+
type.name === "__object" ||
|
|
114
|
+
type.name.startsWith("__type.") ||
|
|
115
|
+
type.name.startsWith("__object.") ||
|
|
116
|
+
type.name.includes("readonly [") ||
|
|
117
|
+
(!!type.typeArguments?.length && type.typeArguments.some(isImplicitType));
|
|
146
118
|
|
|
147
119
|
export const BUNDLE_PATH = NodePath.join(
|
|
148
120
|
__dirname,
|