@nestia/sdk 2.0.0-dev.20230991 → 2.0.1
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/assets/bundle/api/utils/NestiaSimulator.ts +5 -14
- package/lib/INestiaConfig.d.ts +60 -47
- package/lib/NestiaSdkApplication.d.ts +6 -5
- package/lib/NestiaSdkApplication.js +30 -87
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/analyses/ControllerAnalyzer.js +8 -5
- package/lib/analyses/ControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectAnalyzer.js +9 -1
- package/lib/analyses/ReflectAnalyzer.js.map +1 -1
- package/lib/executable/internal/NestiaConfigLoader.d.ts +7 -0
- package/lib/executable/internal/NestiaConfigLoader.js +582 -0
- package/lib/executable/internal/NestiaConfigLoader.js.map +1 -0
- package/lib/executable/internal/NestiaProjectGetter.d.ts +3 -0
- package/lib/executable/internal/NestiaProjectGetter.js +28 -0
- package/lib/executable/internal/NestiaProjectGetter.js.map +1 -0
- package/lib/executable/internal/NestiaSdkCommand.d.ts +3 -3
- package/lib/executable/internal/NestiaSdkCommand.js +13 -104
- package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
- package/lib/executable/internal/{nestia.config.getter.js → nestia.project.getter.js} +3 -3
- package/lib/executable/internal/nestia.project.getter.js.map +1 -0
- package/lib/executable/sdk.js +3 -3
- package/lib/executable/sdk.js.map +1 -1
- package/lib/generates/SdkGenerator.d.ts +2 -1
- package/lib/generates/SdkGenerator.js +7 -3
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +26 -9
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.js +21 -15
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/{DistributionComposer.d.ts → SdkDistributionComposer.d.ts} +1 -1
- package/lib/generates/internal/{DistributionComposer.js → SdkDistributionComposer.js} +8 -12
- package/lib/generates/internal/SdkDistributionComposer.js.map +1 -0
- package/lib/generates/internal/SdkDtoGenerator.d.ts +9 -0
- package/lib/generates/internal/SdkDtoGenerator.js +264 -0
- package/lib/generates/internal/SdkDtoGenerator.js.map +1 -0
- package/lib/generates/internal/SdkFileProgrammer.js +8 -7
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkFunctionProgrammer.js +32 -22
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkImportWizard.d.ts +2 -0
- package/lib/generates/internal/SdkImportWizard.js +10 -0
- package/lib/generates/internal/SdkImportWizard.js.map +1 -1
- package/lib/generates/internal/SdkSimulationProgrammer.js +61 -25
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkTypeDefiner.d.ts +11 -0
- package/lib/generates/internal/SdkTypeDefiner.js +82 -0
- package/lib/generates/internal/SdkTypeDefiner.js.map +1 -0
- package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +1 -1
- package/lib/generates/internal/SwaggerSchemaGenerator.js +67 -75
- package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
- package/lib/generates/internal/SwaggerSchemaValidator.js +0 -8
- package/lib/generates/internal/SwaggerSchemaValidator.js.map +1 -1
- package/lib/structures/IController.d.ts +2 -0
- package/lib/structures/IRoute.d.ts +9 -2
- package/lib/utils/ImportDictionary.d.ts +1 -2
- package/lib/utils/ImportDictionary.js +28 -24
- package/lib/utils/ImportDictionary.js.map +1 -1
- package/package.json +8 -8
- package/src/INestiaConfig.ts +65 -50
- package/src/NestiaSdkApplication.ts +39 -84
- package/src/analyses/ControllerAnalyzer.ts +10 -8
- package/src/analyses/ReflectAnalyzer.ts +8 -0
- package/src/executable/internal/NestiaConfigLoader.ts +82 -0
- package/src/executable/internal/NestiaProjectGetter.ts +11 -0
- package/src/executable/internal/NestiaSdkCommand.ts +23 -146
- package/src/executable/internal/{nestia.config.getter.ts → nestia.project.getter.ts} +2 -2
- package/src/executable/sdk.ts +3 -3
- package/src/generates/SdkGenerator.ts +9 -2
- package/src/generates/SwaggerGenerator.ts +37 -9
- package/src/generates/internal/E2eFileProgrammer.ts +33 -20
- package/src/generates/internal/{DistributionComposer.ts → SdkDistributionComposer.ts} +3 -6
- package/src/generates/internal/SdkDtoGenerator.ts +384 -0
- package/src/generates/internal/SdkFileProgrammer.ts +8 -7
- package/src/generates/internal/SdkFunctionProgrammer.ts +71 -37
- package/src/generates/internal/SdkImportWizard.ts +14 -0
- package/src/generates/internal/SdkSimulationProgrammer.ts +71 -37
- package/src/generates/internal/SdkTypeDefiner.ts +120 -0
- package/src/generates/internal/SwaggerSchemaGenerator.ts +94 -92
- package/src/generates/internal/SwaggerSchemaValidator.ts +0 -12
- package/src/structures/IController.ts +2 -0
- package/src/structures/IRoute.ts +10 -2
- package/src/utils/ImportDictionary.ts +29 -26
- package/lib/executable/internal/NestiaConfigCompilerOptions.d.ts +0 -12
- package/lib/executable/internal/NestiaConfigCompilerOptions.js +0 -18
- package/lib/executable/internal/NestiaConfigCompilerOptions.js.map +0 -1
- package/lib/executable/internal/NestiaSdkConfig.d.ts +0 -4
- package/lib/executable/internal/NestiaSdkConfig.js +0 -1019
- package/lib/executable/internal/NestiaSdkConfig.js.map +0 -1
- package/lib/executable/internal/nestia.config.getter.js.map +0 -1
- package/lib/generates/internal/DistributionComposer.js.map +0 -1
- package/src/executable/internal/NestiaConfigCompilerOptions.ts +0 -19
- package/src/executable/internal/NestiaSdkConfig.ts +0 -36
- /package/lib/executable/internal/{nestia.config.getter.d.ts → nestia.project.getter.d.ts} +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { WorkerConnector } from "tgrid/protocols/workers/WorkerConnector";
|
|
4
|
+
import { register } from "ts-node";
|
|
5
|
+
import { parseNative } from "tsconfck";
|
|
6
|
+
import ts from "typescript";
|
|
7
|
+
|
|
8
|
+
import typia from "typia";
|
|
9
|
+
|
|
10
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
11
|
+
import { NestiaProjectGetter } from "./NestiaProjectGetter";
|
|
12
|
+
|
|
13
|
+
export namespace NestiaConfigLoader {
|
|
14
|
+
export const compilerOptions = async (
|
|
15
|
+
project: string,
|
|
16
|
+
): Promise<ts.CompilerOptions> => {
|
|
17
|
+
const configFileName = ts.findConfigFile(
|
|
18
|
+
process.cwd(),
|
|
19
|
+
ts.sys.fileExists,
|
|
20
|
+
project,
|
|
21
|
+
);
|
|
22
|
+
if (!configFileName)
|
|
23
|
+
throw new Error(`unable to find "tsconfig.json" file.`);
|
|
24
|
+
|
|
25
|
+
const { tsconfig } = await parseNative(configFileName);
|
|
26
|
+
const configFileText = JSON.stringify(tsconfig);
|
|
27
|
+
const { config } = ts.parseConfigFileTextToJson(
|
|
28
|
+
configFileName,
|
|
29
|
+
configFileText,
|
|
30
|
+
);
|
|
31
|
+
const configParseResult = ts.parseJsonConfigFileContent(
|
|
32
|
+
config,
|
|
33
|
+
ts.sys,
|
|
34
|
+
path.dirname(configFileName),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const { moduleResolution, ...result } =
|
|
38
|
+
configParseResult.raw.compilerOptions;
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const config = async (
|
|
43
|
+
options: ts.CompilerOptions,
|
|
44
|
+
): Promise<INestiaConfig> => {
|
|
45
|
+
if (fs.existsSync(path.resolve("nestia.config.ts")) === false)
|
|
46
|
+
throw new Error(`unable to find "nestia.config.ts" file.`);
|
|
47
|
+
|
|
48
|
+
register({
|
|
49
|
+
emit: false,
|
|
50
|
+
compilerOptions: options,
|
|
51
|
+
require: options.baseUrl ? ["tsconfig-paths/register"] : undefined,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const loaded: INestiaConfig & { default?: INestiaConfig } =
|
|
55
|
+
await import(path.resolve("nestia.config.ts"));
|
|
56
|
+
const config: INestiaConfig =
|
|
57
|
+
typeof loaded?.default === "object" && loaded.default !== null
|
|
58
|
+
? loaded.default
|
|
59
|
+
: loaded;
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
return typia.assert(config);
|
|
63
|
+
} catch (exp) {
|
|
64
|
+
if (typia.is<typia.TypeGuardError>(exp))
|
|
65
|
+
exp.message = `invalid "nestia.config.ts" data.`;
|
|
66
|
+
throw exp;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const project = async (): Promise<string> => {
|
|
71
|
+
const connector = new WorkerConnector(null, null, "process");
|
|
72
|
+
await connector.connect(
|
|
73
|
+
`${__dirname}/nestia.project.getter.${__filename.substr(-2)}`,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const driver = await connector.getDriver<typeof NestiaProjectGetter>();
|
|
77
|
+
const project: string = await driver.get();
|
|
78
|
+
await connector.close();
|
|
79
|
+
|
|
80
|
+
return project;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NestiaConfigLoader } from "./NestiaConfigLoader";
|
|
2
|
+
|
|
3
|
+
export namespace NestiaProjectGetter {
|
|
4
|
+
export async function get(): Promise<string> {
|
|
5
|
+
const config = await NestiaConfigLoader.config({
|
|
6
|
+
module: "CommonJS" as any,
|
|
7
|
+
noEmit: true,
|
|
8
|
+
});
|
|
9
|
+
return config.project ?? "tsconfig.json";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,157 +1,34 @@
|
|
|
1
|
-
import cli from "cli";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { WorkerConnector } from "tgrid/protocols/workers/WorkerConnector";
|
|
4
|
-
import { parseNative } from "tsconfck";
|
|
5
1
|
import ts from "typescript";
|
|
6
2
|
|
|
7
3
|
import { INestiaConfig } from "../../INestiaConfig";
|
|
8
4
|
import { NestiaSdkApplication } from "../../NestiaSdkApplication";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
interface ICommand {
|
|
12
|
-
exclude: string | null;
|
|
13
|
-
out: string | null;
|
|
14
|
-
e2e: string | null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface IProps {
|
|
18
|
-
assign: (config: INestiaConfig, output: string) => void;
|
|
19
|
-
validate: (config: INestiaConfig) => boolean;
|
|
20
|
-
location: (config: INestiaConfig) => string;
|
|
21
|
-
}
|
|
5
|
+
import { NestiaConfigLoader } from "./NestiaConfigLoader";
|
|
22
6
|
|
|
23
7
|
export namespace NestiaSdkCommand {
|
|
24
|
-
export const sdk = (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export const e2e = (argv: string[]) =>
|
|
42
|
-
main({
|
|
43
|
-
assign: (config, output) => (config.output = output),
|
|
44
|
-
validate: (config) => !!config.output,
|
|
45
|
-
location: (config) => config.output!,
|
|
46
|
-
})(argv)((app) => app.e2e());
|
|
47
|
-
|
|
48
|
-
const main =
|
|
49
|
-
(props: IProps) =>
|
|
50
|
-
(argv: string[]) =>
|
|
51
|
-
async (task: (app: NestiaSdkApplication) => Promise<void>) => {
|
|
52
|
-
const command: ICommand = cli.parse({
|
|
53
|
-
exclude: ["e", "Something to exclude", "string", null],
|
|
54
|
-
out: ["o", "Output path of the SDK files", "string", null],
|
|
55
|
-
e2e: [
|
|
56
|
-
"e",
|
|
57
|
-
"Output path of e2e test function files",
|
|
58
|
-
"string",
|
|
59
|
-
null,
|
|
60
|
-
],
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const inputs: string[] = [];
|
|
64
|
-
for (const r of argv) {
|
|
65
|
-
if (r[0] === "-") break;
|
|
66
|
-
inputs.push(r);
|
|
67
|
-
}
|
|
68
|
-
await generate(props)(command)(inputs)(task);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const generate =
|
|
72
|
-
(props: IProps) =>
|
|
73
|
-
(command: ICommand) =>
|
|
74
|
-
(include: string[]) =>
|
|
75
|
-
async (task: (app: NestiaSdkApplication) => Promise<void>) => {
|
|
76
|
-
// CONFIGURATION
|
|
77
|
-
const config: INestiaConfig =
|
|
78
|
-
(await get_nestia_config(props.validate)) ??
|
|
79
|
-
parse_cli(props)(command)(include);
|
|
80
|
-
|
|
81
|
-
const options: ts.CompilerOptions | null =
|
|
82
|
-
await get_typescript_options();
|
|
83
|
-
config.compilerOptions = {
|
|
84
|
-
...(options ?? {}),
|
|
85
|
-
...(config.compilerOptions ?? {}),
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// CALL THE APP.GENERATE()
|
|
89
|
-
const app: NestiaSdkApplication = new NestiaSdkApplication(config);
|
|
90
|
-
await task(app);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
async function get_typescript_options(): Promise<ts.CompilerOptions | null> {
|
|
94
|
-
const configFileName = ts.findConfigFile(
|
|
95
|
-
process.cwd(),
|
|
96
|
-
ts.sys.fileExists,
|
|
97
|
-
"tsconfig.json",
|
|
8
|
+
export const sdk = () => main((app) => app.sdk());
|
|
9
|
+
export const swagger = () => main((app) => app.swagger());
|
|
10
|
+
export const e2e = () => main((app) => app.e2e());
|
|
11
|
+
|
|
12
|
+
const main = async (task: (app: NestiaSdkApplication) => Promise<void>) => {
|
|
13
|
+
await generate(task);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const generate = async (
|
|
17
|
+
task: (app: NestiaSdkApplication) => Promise<void>,
|
|
18
|
+
) => {
|
|
19
|
+
// LOAD CONFIG INFO
|
|
20
|
+
const project: string = await NestiaConfigLoader.project();
|
|
21
|
+
const compilerOptions: ts.CompilerOptions =
|
|
22
|
+
await NestiaConfigLoader.compilerOptions(project);
|
|
23
|
+
const config: INestiaConfig = await NestiaConfigLoader.config(
|
|
24
|
+
compilerOptions,
|
|
98
25
|
);
|
|
99
|
-
if (!configFileName) return null;
|
|
100
26
|
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
const { config } = ts.parseConfigFileTextToJson(
|
|
104
|
-
configFileName,
|
|
105
|
-
configFileText,
|
|
106
|
-
);
|
|
107
|
-
const configParseResult = ts.parseJsonConfigFileContent(
|
|
27
|
+
// GENERATE
|
|
28
|
+
const app: NestiaSdkApplication = new NestiaSdkApplication(
|
|
108
29
|
config,
|
|
109
|
-
|
|
110
|
-
path.dirname(configFileName),
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const { moduleResolution, ...result } =
|
|
114
|
-
configParseResult.raw.compilerOptions;
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async function get_nestia_config(
|
|
119
|
-
validate: (config: INestiaConfig) => boolean,
|
|
120
|
-
): Promise<INestiaConfig | null> {
|
|
121
|
-
const connector = new WorkerConnector(null, null, "process");
|
|
122
|
-
await connector.connect(
|
|
123
|
-
`${__dirname}/nestia.config.getter.${__filename.substr(-2)}`,
|
|
30
|
+
compilerOptions,
|
|
124
31
|
);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const config: INestiaConfig | null = await driver.get();
|
|
128
|
-
await connector.close();
|
|
129
|
-
|
|
130
|
-
if (config !== null && validate(config) === false)
|
|
131
|
-
throw new Error(
|
|
132
|
-
`Error on NestiaCommand.main(): output path is not specified in the "nestia.config.ts".`,
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
return config;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const parse_cli =
|
|
139
|
-
(props: IProps) =>
|
|
140
|
-
(command: ICommand) =>
|
|
141
|
-
(include: string[]): INestiaConfig => {
|
|
142
|
-
if (command.out === null)
|
|
143
|
-
throw new Error(
|
|
144
|
-
`Error on NestiaCommand.main(): output directory is not specified. Add the "--out <output_directory>" option.`,
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
const config: INestiaConfig = {
|
|
148
|
-
input: {
|
|
149
|
-
include,
|
|
150
|
-
exclude: command.exclude ? [command.exclude] : undefined,
|
|
151
|
-
},
|
|
152
|
-
e2e: command.e2e ?? undefined,
|
|
153
|
-
};
|
|
154
|
-
props.assign(config, command.out);
|
|
155
|
-
return config;
|
|
156
|
-
};
|
|
32
|
+
await task(app);
|
|
33
|
+
};
|
|
157
34
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { WorkerServer } from "tgrid/protocols/workers/WorkerServer";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { NestiaProjectGetter } from "./NestiaProjectGetter";
|
|
4
4
|
|
|
5
5
|
async function main(): Promise<void> {
|
|
6
6
|
const worker = new WorkerServer();
|
|
7
|
-
await worker.open(
|
|
7
|
+
await worker.open(NestiaProjectGetter);
|
|
8
8
|
}
|
|
9
9
|
main().catch((exp) => {
|
|
10
10
|
console.log(exp);
|
package/src/executable/sdk.ts
CHANGED
|
@@ -59,9 +59,9 @@ async function main() {
|
|
|
59
59
|
|
|
60
60
|
if (type === "dependencies") dependencies(argv);
|
|
61
61
|
else if (type === "init") await initialize();
|
|
62
|
-
else if (type === "sdk") await execute((c) => c.sdk(
|
|
63
|
-
else if (type === "swagger") await execute((c) => c.swagger(
|
|
64
|
-
else if (type === "e2e") await execute((c) => c.e2e(
|
|
62
|
+
else if (type === "sdk") await execute((c) => c.sdk());
|
|
63
|
+
else if (type === "swagger") await execute((c) => c.swagger());
|
|
64
|
+
else if (type === "e2e") await execute((c) => c.e2e());
|
|
65
65
|
else halt(USAGE);
|
|
66
66
|
}
|
|
67
67
|
main().catch((exp) => {
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import NodePath from "path";
|
|
3
3
|
import { IPointer } from "tstl";
|
|
4
|
+
import ts from "typescript";
|
|
4
5
|
|
|
5
6
|
import { INestiaConfig } from "../INestiaConfig";
|
|
6
7
|
import { IRoute } from "../structures/IRoute";
|
|
7
|
-
import {
|
|
8
|
+
import { SdkDistributionComposer } from "./internal/SdkDistributionComposer";
|
|
9
|
+
import { SdkDtoGenerator } from "./internal/SdkDtoGenerator";
|
|
8
10
|
import { SdkFileProgrammer } from "./internal/SdkFileProgrammer";
|
|
9
11
|
|
|
10
12
|
export namespace SdkGenerator {
|
|
11
13
|
export const generate =
|
|
14
|
+
(checker: ts.TypeChecker) =>
|
|
12
15
|
(config: INestiaConfig) =>
|
|
13
16
|
async (routes: IRoute[]): Promise<void> => {
|
|
14
17
|
console.log("Generating SDK Library");
|
|
@@ -55,12 +58,16 @@ export namespace SdkGenerator {
|
|
|
55
58
|
);
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
// STRUCTURES
|
|
62
|
+
if (config.clone)
|
|
63
|
+
await SdkDtoGenerator.generate(checker)(config)(routes);
|
|
64
|
+
|
|
58
65
|
// FUNCTIONAL
|
|
59
66
|
await SdkFileProgrammer.generate(config)(routes);
|
|
60
67
|
|
|
61
68
|
// DISTRIBUTION
|
|
62
69
|
if (config.distribute !== undefined)
|
|
63
|
-
await
|
|
70
|
+
await SdkDistributionComposer.compose(config);
|
|
64
71
|
};
|
|
65
72
|
|
|
66
73
|
export const BUNDLE_PATH = NodePath.join(
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import NodePath from "path";
|
|
3
|
+
import path from "path";
|
|
3
4
|
import { Singleton } from "tstl/thread/Singleton";
|
|
4
5
|
import ts from "typescript";
|
|
5
6
|
|
|
@@ -70,7 +71,8 @@ export namespace SwaggerGenerator {
|
|
|
70
71
|
> = new Map();
|
|
71
72
|
|
|
72
73
|
for (const route of routeList) {
|
|
73
|
-
if (route.
|
|
74
|
+
if (route.jsDocTags.find((tag) => tag.name === "internal"))
|
|
75
|
+
continue;
|
|
74
76
|
|
|
75
77
|
const path: Record<string, ISwaggerRoute> = MapUtil.take(
|
|
76
78
|
pathDict,
|
|
@@ -106,6 +108,21 @@ export namespace SwaggerGenerator {
|
|
|
106
108
|
// CONFIGURE SECURITY
|
|
107
109
|
if (config.security) fill_security(config.security, swagger);
|
|
108
110
|
|
|
111
|
+
// REPORT ERRORS
|
|
112
|
+
if (errors.length) {
|
|
113
|
+
for (const e of errors)
|
|
114
|
+
console.error(
|
|
115
|
+
`${path.relative(e.route.location, process.cwd())}:${
|
|
116
|
+
e.route.symbol.class
|
|
117
|
+
}.${e.route.symbol.function}:${
|
|
118
|
+
e.from
|
|
119
|
+
} - error TS(@nestia/sdk): invalid type detected.\n\n` +
|
|
120
|
+
e.messages.map((m) => ` - ${m}`).join("\n"),
|
|
121
|
+
"\n\n",
|
|
122
|
+
);
|
|
123
|
+
throw new TypeError("Invalid type detected");
|
|
124
|
+
}
|
|
125
|
+
|
|
109
126
|
// DO GENERATE
|
|
110
127
|
await fs.promises.writeFile(
|
|
111
128
|
location,
|
|
@@ -281,8 +298,8 @@ export namespace SwaggerGenerator {
|
|
|
281
298
|
const body = route.parameters.find(
|
|
282
299
|
(param) => param.category === "body",
|
|
283
300
|
);
|
|
284
|
-
const
|
|
285
|
-
route.
|
|
301
|
+
const getJsDocTexts = (name: string) =>
|
|
302
|
+
route.jsDocTags
|
|
286
303
|
.filter(
|
|
287
304
|
(tag) =>
|
|
288
305
|
tag.name === name &&
|
|
@@ -304,7 +321,7 @@ export namespace SwaggerGenerator {
|
|
|
304
321
|
const summary: string | undefined = (() => {
|
|
305
322
|
if (description === undefined) return undefined;
|
|
306
323
|
|
|
307
|
-
const [explicit] =
|
|
324
|
+
const [explicit] = getJsDocTexts("summary");
|
|
308
325
|
if (explicit?.length) return explicit;
|
|
309
326
|
|
|
310
327
|
const index: number = description.indexOf(".");
|
|
@@ -313,19 +330,30 @@ export namespace SwaggerGenerator {
|
|
|
313
330
|
const content: string = description.substring(0, index).trim();
|
|
314
331
|
return content.length ? content : undefined;
|
|
315
332
|
})();
|
|
316
|
-
const deprecated = route.
|
|
333
|
+
const deprecated = route.jsDocTags.find(
|
|
317
334
|
(tag) => tag.name === "deprecated",
|
|
318
335
|
);
|
|
319
336
|
|
|
320
337
|
return {
|
|
321
338
|
deprecated: deprecated ? true : undefined,
|
|
322
|
-
tags:
|
|
323
|
-
|
|
339
|
+
tags: [
|
|
340
|
+
...route.swaggerTags,
|
|
341
|
+
...new Set([...getJsDocTexts("tag")]),
|
|
342
|
+
],
|
|
343
|
+
operationId:
|
|
344
|
+
route.operationId ??
|
|
345
|
+
props.config.operationId?.({
|
|
346
|
+
class: route.symbol.class,
|
|
347
|
+
function: route.symbol.function,
|
|
348
|
+
method: route.method as "GET",
|
|
349
|
+
path: route.path,
|
|
350
|
+
}),
|
|
324
351
|
parameters: route.parameters
|
|
325
352
|
.filter((param) => param.category !== "body")
|
|
326
353
|
.map((param) =>
|
|
327
354
|
SwaggerSchemaGenerator.parameter(props)(route)(param),
|
|
328
|
-
)
|
|
355
|
+
)
|
|
356
|
+
.flat(),
|
|
329
357
|
requestBody: body
|
|
330
358
|
? SwaggerSchemaGenerator.body(props)(route)(body)
|
|
331
359
|
: undefined,
|
|
@@ -339,7 +367,7 @@ export namespace SwaggerGenerator {
|
|
|
339
367
|
.filter((str) => str.length && str[0] !== ":"),
|
|
340
368
|
route.name,
|
|
341
369
|
].join("."),
|
|
342
|
-
"x-nestia-jsDocTags": route.
|
|
370
|
+
"x-nestia-jsDocTags": route.jsDocTags,
|
|
343
371
|
"x-nestia-method": route.method,
|
|
344
372
|
};
|
|
345
373
|
};
|
|
@@ -3,6 +3,7 @@ import fs from "fs";
|
|
|
3
3
|
import { INestiaConfig } from "../../INestiaConfig";
|
|
4
4
|
import { IRoute } from "../../structures/IRoute";
|
|
5
5
|
import { ImportDictionary } from "../../utils/ImportDictionary";
|
|
6
|
+
import { SdkDtoGenerator } from "./SdkDtoGenerator";
|
|
6
7
|
import { SdkImportWizard } from "./SdkImportWizard";
|
|
7
8
|
|
|
8
9
|
export namespace E2eFileProgrammer {
|
|
@@ -11,20 +12,21 @@ export namespace E2eFileProgrammer {
|
|
|
11
12
|
(props: { api: string; current: string }) =>
|
|
12
13
|
async (route: IRoute): Promise<void> => {
|
|
13
14
|
const importer: ImportDictionary = new ImportDictionary();
|
|
14
|
-
|
|
15
|
-
for (const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
if (config.clone !== true)
|
|
16
|
+
for (const tuple of route.imports)
|
|
17
|
+
for (const instance of tuple[1])
|
|
18
|
+
importer.internal({
|
|
19
|
+
file: tuple[0],
|
|
20
|
+
type: true,
|
|
21
|
+
instance,
|
|
22
|
+
});
|
|
22
23
|
importer.internal({
|
|
23
24
|
type: false,
|
|
24
25
|
file: props.api,
|
|
25
26
|
instance: null,
|
|
26
27
|
name: "api",
|
|
27
28
|
});
|
|
29
|
+
|
|
28
30
|
const body: string = arrow(config)(importer)(route);
|
|
29
31
|
const content: string = [
|
|
30
32
|
importer.toScript(props.current),
|
|
@@ -43,7 +45,7 @@ export namespace E2eFileProgrammer {
|
|
|
43
45
|
(config: INestiaConfig) =>
|
|
44
46
|
(importer: ImportDictionary) =>
|
|
45
47
|
(route: IRoute): string => {
|
|
46
|
-
const tab: number =
|
|
48
|
+
const tab: number = 2;
|
|
47
49
|
const headers = route.parameters.find(
|
|
48
50
|
(p) => p.category === "headers" && p.field === undefined,
|
|
49
51
|
);
|
|
@@ -57,7 +59,9 @@ export namespace E2eFileProgrammer {
|
|
|
57
59
|
" ...(connection.headers ?? {}),",
|
|
58
60
|
` ...${SdkImportWizard.typia(
|
|
59
61
|
importer,
|
|
60
|
-
)}.random<${
|
|
62
|
+
)}.random<${getTypeName(config)(importer)(
|
|
63
|
+
headers,
|
|
64
|
+
)}>(),`,
|
|
61
65
|
" },",
|
|
62
66
|
"},",
|
|
63
67
|
]
|
|
@@ -76,10 +80,7 @@ export namespace E2eFileProgrammer {
|
|
|
76
80
|
...(route.output.typeName === "void"
|
|
77
81
|
? [` ${output}`]
|
|
78
82
|
: [
|
|
79
|
-
` const output
|
|
80
|
-
route.output.typeName,
|
|
81
|
-
)} = `,
|
|
82
|
-
` ${output}`,
|
|
83
|
+
` const output = ${output}`,
|
|
83
84
|
` ${SdkImportWizard.typia(
|
|
84
85
|
importer,
|
|
85
86
|
)}.assert(output);`,
|
|
@@ -95,7 +96,10 @@ export namespace E2eFileProgrammer {
|
|
|
95
96
|
(param: IRoute.IParameter): string => {
|
|
96
97
|
const middle: string = `${SdkImportWizard.typia(
|
|
97
98
|
importer,
|
|
98
|
-
)}.random<${
|
|
99
|
+
)}.random<${wrap(config)(importer)(
|
|
100
|
+
getTypeName(config)(importer)(param),
|
|
101
|
+
param.category === "body",
|
|
102
|
+
)}>()`;
|
|
99
103
|
return `${" ".repeat(4 * tab)}${middle},`;
|
|
100
104
|
};
|
|
101
105
|
|
|
@@ -105,11 +109,20 @@ export namespace E2eFileProgrammer {
|
|
|
105
109
|
const accessor = (route: IRoute): string =>
|
|
106
110
|
["api", "functional", ...route.accessors].join(".");
|
|
107
111
|
|
|
108
|
-
const
|
|
112
|
+
const wrap =
|
|
109
113
|
(config: INestiaConfig) =>
|
|
110
114
|
(importer: ImportDictionary) =>
|
|
111
|
-
(name: string): string =>
|
|
112
|
-
config.primitive
|
|
113
|
-
?
|
|
114
|
-
:
|
|
115
|
+
(name: string, body: boolean): string =>
|
|
116
|
+
config.primitive === false
|
|
117
|
+
? name
|
|
118
|
+
: `${(body
|
|
119
|
+
? SdkImportWizard.Primitive
|
|
120
|
+
: SdkImportWizard.Resolved)(importer)}<${name}>`;
|
|
115
121
|
}
|
|
122
|
+
const getTypeName =
|
|
123
|
+
(config: INestiaConfig) =>
|
|
124
|
+
(importer: ImportDictionary) =>
|
|
125
|
+
(p: IRoute.IParameter | IRoute.IOutput) =>
|
|
126
|
+
p.metadata
|
|
127
|
+
? SdkDtoGenerator.decode(config)(importer)(p.metadata)
|
|
128
|
+
: p.typeName;
|
|
@@ -4,7 +4,7 @@ import path from "path";
|
|
|
4
4
|
|
|
5
5
|
import { INestiaConfig } from "../../INestiaConfig";
|
|
6
6
|
|
|
7
|
-
export namespace
|
|
7
|
+
export namespace SdkDistributionComposer {
|
|
8
8
|
export const compose = async (config: INestiaConfig): Promise<void> => {
|
|
9
9
|
if (!fs.existsSync(config.distribute!))
|
|
10
10
|
await fs.promises.mkdir(config.distribute!);
|
|
@@ -40,11 +40,8 @@ export namespace DistributionComposer {
|
|
|
40
40
|
execute(
|
|
41
41
|
`npm install --save @nestia/fetcher@${versions["@nestia/fetcher"]}`,
|
|
42
42
|
);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
execute(`npm install --save typia@${versions["typia"]}`);
|
|
46
|
-
execute("npx typia setup --manager npm");
|
|
47
|
-
} else execute("npm install --save-dev typescript");
|
|
43
|
+
execute(`npm install --save typia@${versions["typia"]}`);
|
|
44
|
+
execute("npx typia setup --manager npm");
|
|
48
45
|
|
|
49
46
|
exit();
|
|
50
47
|
};
|