@nestia/sdk 1.3.2 → 1.3.4

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.
Files changed (51) hide show
  1. package/assets/config/nestia.config.ts +70 -70
  2. package/lib/INestiaConfig.d.ts +13 -0
  3. package/lib/executable/internal/NestiaSdkConfig.js +6 -2
  4. package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
  5. package/lib/executable/sdk.js +11 -11
  6. package/lib/generates/SwaggerGenerator.js +9 -9
  7. package/lib/generates/internal/DistributionComposer.js +1 -1
  8. package/lib/generates/internal/DistributionComposer.js.map +1 -1
  9. package/lib/generates/internal/E2eFileProgrammer.js +12 -12
  10. package/lib/generates/internal/SdkFileProgrammer.js +7 -5
  11. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  12. package/lib/generates/internal/SdkFunctionProgrammer.js +42 -49
  13. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  14. package/package.json +6 -4
  15. package/src/INestiaConfig.ts +204 -190
  16. package/src/NestiaSdkApplication.ts +262 -262
  17. package/src/analyses/ControllerAnalyzer.ts +261 -261
  18. package/src/analyses/GenericAnalyzer.ts +53 -53
  19. package/src/analyses/ImportAnalyzer.ts +164 -164
  20. package/src/analyses/PathAnalyzer.ts +58 -58
  21. package/src/analyses/ReflectAnalyzer.ts +321 -321
  22. package/src/executable/internal/CommandParser.ts +15 -15
  23. package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -18
  24. package/src/executable/internal/NestiaSdkCommand.ts +156 -156
  25. package/src/executable/internal/NestiaSdkConfig.ts +36 -36
  26. package/src/executable/internal/nestia.config.getter.ts +12 -12
  27. package/src/executable/sdk.ts +70 -70
  28. package/src/generates/E2eGenerator.ts +67 -67
  29. package/src/generates/SdkGenerator.ts +56 -56
  30. package/src/generates/SwaggerGenerator.ts +504 -504
  31. package/src/generates/internal/DistributionComposer.ts +98 -97
  32. package/src/generates/internal/E2eFileProgrammer.ts +135 -135
  33. package/src/generates/internal/SdkFileProgrammer.ts +150 -144
  34. package/src/generates/internal/SdkFunctionProgrammer.ts +51 -58
  35. package/src/generates/internal/SdkRouteDirectory.ts +21 -21
  36. package/src/index.ts +4 -4
  37. package/src/module.ts +2 -2
  38. package/src/structures/IController.ts +31 -31
  39. package/src/structures/IRoute.ts +39 -39
  40. package/src/structures/ISwaggerDocument.ts +120 -120
  41. package/src/structures/ITypeTuple.ts +6 -6
  42. package/src/structures/MethodType.ts +11 -11
  43. package/src/structures/ParamCategory.ts +1 -1
  44. package/src/structures/TypeEntry.ts +22 -22
  45. package/src/utils/ArrayUtil.ts +26 -26
  46. package/src/utils/FileRetriever.ts +22 -22
  47. package/src/utils/ImportDictionary.ts +56 -56
  48. package/src/utils/MapUtil.ts +14 -14
  49. package/src/utils/NestiaConfigUtil.ts +21 -21
  50. package/src/utils/SourceFinder.ts +60 -60
  51. package/src/utils/StripEnums.ts +10 -10
@@ -1,18 +1,18 @@
1
- export namespace NestiaConfigCompilerOptions {
2
- /* -----------------------------------------------------------
3
- DEFAULT VALUES
4
- ----------------------------------------------------------- */
5
- const ESSENTIAL_OPTIONS = {
6
- types: ["node", "reflect-metadata"],
7
- noEmit: true,
8
- esModuleInterop: true,
9
- experimentalDecorators: true,
10
- emitDecoratorMetadata: true,
11
- };
12
-
13
- export const DEFAULT_OPTIONS = {
14
- ...ESSENTIAL_OPTIONS,
15
- target: "es5",
16
- module: "commonjs",
17
- };
18
- }
1
+ export namespace NestiaConfigCompilerOptions {
2
+ /* -----------------------------------------------------------
3
+ DEFAULT VALUES
4
+ ----------------------------------------------------------- */
5
+ const ESSENTIAL_OPTIONS = {
6
+ types: ["node", "reflect-metadata"],
7
+ noEmit: true,
8
+ esModuleInterop: true,
9
+ experimentalDecorators: true,
10
+ emitDecoratorMetadata: true,
11
+ };
12
+
13
+ export const DEFAULT_OPTIONS = {
14
+ ...ESSENTIAL_OPTIONS,
15
+ target: "es5",
16
+ module: "commonjs",
17
+ };
18
+ }
@@ -1,156 +1,156 @@
1
- import cli from "cli";
2
- import path from "path";
3
- import { WorkerConnector } from "tgrid/protocols/workers/WorkerConnector";
4
- import { parseNative } from "tsconfck";
5
- import ts from "typescript";
6
-
7
- import { INestiaConfig } from "../../INestiaConfig";
8
- import { NestiaSdkApplication } from "../../NestiaSdkApplication";
9
- import { NestiaSdkConfig } from "./NestiaSdkConfig";
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
- }
22
-
23
- export namespace NestiaSdkCommand {
24
- export const sdk = (argv: string[]) =>
25
- main({
26
- assign: (config, output) => (config.output = output),
27
- validate: (config) => !!config.output,
28
- location: (config) => config.output!,
29
- })(argv)((app) => app.sdk());
30
-
31
- export const swagger = (argv: string[]) =>
32
- main({
33
- assign: (config, output) => {
34
- if (!config.swagger) config.swagger = { output };
35
- else config.swagger.output = output;
36
- },
37
- validate: (config) => !!config.swagger && !!config.swagger.output,
38
- location: (config) => config.swagger!.output!,
39
- })(argv)((app) => app.swagger());
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 = await get_typescript_options();
82
- config.compilerOptions = {
83
- ...options,
84
- ...(config.compilerOptions || {}),
85
- };
86
-
87
- // CALL THE APP.GENERATE()
88
- const app: NestiaSdkApplication = new NestiaSdkApplication(config);
89
- await task(app);
90
- };
91
-
92
- async function get_typescript_options(): Promise<ts.CompilerOptions | null> {
93
- const configFileName = ts.findConfigFile(
94
- process.cwd(),
95
- ts.sys.fileExists,
96
- "tsconfig.json",
97
- );
98
- if (!configFileName) return null;
99
-
100
- const { tsconfig } = await parseNative(configFileName);
101
- const configFileText = JSON.stringify(tsconfig);
102
- const { config } = ts.parseConfigFileTextToJson(
103
- configFileName,
104
- configFileText,
105
- );
106
- const configParseResult = ts.parseJsonConfigFileContent(
107
- config,
108
- ts.sys,
109
- path.dirname(configFileName),
110
- );
111
-
112
- const { moduleResolution, ...result } =
113
- configParseResult.raw.compilerOptions;
114
- return result;
115
- }
116
-
117
- async function get_nestia_config(
118
- validate: (config: INestiaConfig) => boolean,
119
- ): Promise<INestiaConfig | null> {
120
- const connector = new WorkerConnector(null, null, "process");
121
- await connector.connect(
122
- `${__dirname}/nestia.config.getter.${__filename.substr(-2)}`,
123
- );
124
-
125
- const driver = await connector.getDriver<typeof NestiaSdkConfig>();
126
- const config: INestiaConfig | null = await driver.get();
127
- await connector.close();
128
-
129
- if (config !== null && validate(config) === false)
130
- throw new Error(
131
- `Error on NestiaCommand.main(): output path is not specified in the "nestia.config.ts".`,
132
- );
133
-
134
- return config;
135
- }
136
-
137
- const parse_cli =
138
- (props: IProps) =>
139
- (command: ICommand) =>
140
- (include: string[]): INestiaConfig => {
141
- if (command.out === null)
142
- throw new Error(
143
- `Error on NestiaCommand.main(): output directory is not specified. Add the "--out <output_directory>" option.`,
144
- );
145
-
146
- const config: INestiaConfig = {
147
- input: {
148
- include,
149
- exclude: command.exclude ? [command.exclude] : undefined,
150
- },
151
- e2e: command.e2e ?? undefined,
152
- };
153
- props.assign(config, command.out);
154
- return config;
155
- };
156
- }
1
+ import cli from "cli";
2
+ import path from "path";
3
+ import { WorkerConnector } from "tgrid/protocols/workers/WorkerConnector";
4
+ import { parseNative } from "tsconfck";
5
+ import ts from "typescript";
6
+
7
+ import { INestiaConfig } from "../../INestiaConfig";
8
+ import { NestiaSdkApplication } from "../../NestiaSdkApplication";
9
+ import { NestiaSdkConfig } from "./NestiaSdkConfig";
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
+ }
22
+
23
+ export namespace NestiaSdkCommand {
24
+ export const sdk = (argv: string[]) =>
25
+ main({
26
+ assign: (config, output) => (config.output = output),
27
+ validate: (config) => !!config.output,
28
+ location: (config) => config.output!,
29
+ })(argv)((app) => app.sdk());
30
+
31
+ export const swagger = (argv: string[]) =>
32
+ main({
33
+ assign: (config, output) => {
34
+ if (!config.swagger) config.swagger = { output };
35
+ else config.swagger.output = output;
36
+ },
37
+ validate: (config) => !!config.swagger && !!config.swagger.output,
38
+ location: (config) => config.swagger!.output!,
39
+ })(argv)((app) => app.swagger());
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 = await get_typescript_options();
82
+ config.compilerOptions = {
83
+ ...options,
84
+ ...(config.compilerOptions || {}),
85
+ };
86
+
87
+ // CALL THE APP.GENERATE()
88
+ const app: NestiaSdkApplication = new NestiaSdkApplication(config);
89
+ await task(app);
90
+ };
91
+
92
+ async function get_typescript_options(): Promise<ts.CompilerOptions | null> {
93
+ const configFileName = ts.findConfigFile(
94
+ process.cwd(),
95
+ ts.sys.fileExists,
96
+ "tsconfig.json",
97
+ );
98
+ if (!configFileName) return null;
99
+
100
+ const { tsconfig } = await parseNative(configFileName);
101
+ const configFileText = JSON.stringify(tsconfig);
102
+ const { config } = ts.parseConfigFileTextToJson(
103
+ configFileName,
104
+ configFileText,
105
+ );
106
+ const configParseResult = ts.parseJsonConfigFileContent(
107
+ config,
108
+ ts.sys,
109
+ path.dirname(configFileName),
110
+ );
111
+
112
+ const { moduleResolution, ...result } =
113
+ configParseResult.raw.compilerOptions;
114
+ return result;
115
+ }
116
+
117
+ async function get_nestia_config(
118
+ validate: (config: INestiaConfig) => boolean,
119
+ ): Promise<INestiaConfig | null> {
120
+ const connector = new WorkerConnector(null, null, "process");
121
+ await connector.connect(
122
+ `${__dirname}/nestia.config.getter.${__filename.substr(-2)}`,
123
+ );
124
+
125
+ const driver = await connector.getDriver<typeof NestiaSdkConfig>();
126
+ const config: INestiaConfig | null = await driver.get();
127
+ await connector.close();
128
+
129
+ if (config !== null && validate(config) === false)
130
+ throw new Error(
131
+ `Error on NestiaCommand.main(): output path is not specified in the "nestia.config.ts".`,
132
+ );
133
+
134
+ return config;
135
+ }
136
+
137
+ const parse_cli =
138
+ (props: IProps) =>
139
+ (command: ICommand) =>
140
+ (include: string[]): INestiaConfig => {
141
+ if (command.out === null)
142
+ throw new Error(
143
+ `Error on NestiaCommand.main(): output directory is not specified. Add the "--out <output_directory>" option.`,
144
+ );
145
+
146
+ const config: INestiaConfig = {
147
+ input: {
148
+ include,
149
+ exclude: command.exclude ? [command.exclude] : undefined,
150
+ },
151
+ e2e: command.e2e ?? undefined,
152
+ };
153
+ props.assign(config, command.out);
154
+ return config;
155
+ };
156
+ }
@@ -1,36 +1,36 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import * as runner from "ts-node";
4
- import { Singleton } from "tstl/thread/Singleton";
5
-
6
- import { assert } from "typia";
7
-
8
- import { INestiaConfig } from "../../INestiaConfig";
9
-
10
- export namespace NestiaSdkConfig {
11
- export function get(): Promise<INestiaConfig | null> {
12
- return singleton.get();
13
- }
14
-
15
- const singleton = new Singleton(async () => {
16
- if (fs.existsSync("nestia.config.ts") === false) return null;
17
-
18
- runner.register({
19
- emit: false,
20
- compilerOptions: {
21
- module: "CommonJS",
22
- noEmit: true,
23
- },
24
- });
25
-
26
- const loaded: INestiaConfig & { default?: INestiaConfig } =
27
- await import(path.resolve("nestia.config.ts"));
28
- if (typeof loaded !== "object")
29
- throw new Error("Error on NestiaConfig.get(): failed to load data");
30
-
31
- const config: INestiaConfig =
32
- typeof loaded.default === "object" ? loaded.default : loaded;
33
- const cloned: INestiaConfig = JSON.parse(JSON.stringify(config));
34
- return assert(cloned);
35
- });
36
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import * as runner from "ts-node";
4
+ import { Singleton } from "tstl/thread/Singleton";
5
+
6
+ import { assert } from "typia";
7
+
8
+ import { INestiaConfig } from "../../INestiaConfig";
9
+
10
+ export namespace NestiaSdkConfig {
11
+ export function get(): Promise<INestiaConfig | null> {
12
+ return singleton.get();
13
+ }
14
+
15
+ const singleton = new Singleton(async () => {
16
+ if (fs.existsSync("nestia.config.ts") === false) return null;
17
+
18
+ runner.register({
19
+ emit: false,
20
+ compilerOptions: {
21
+ module: "CommonJS",
22
+ noEmit: true,
23
+ },
24
+ });
25
+
26
+ const loaded: INestiaConfig & { default?: INestiaConfig } =
27
+ await import(path.resolve("nestia.config.ts"));
28
+ if (typeof loaded !== "object")
29
+ throw new Error("Error on NestiaConfig.get(): failed to load data");
30
+
31
+ const config: INestiaConfig =
32
+ typeof loaded.default === "object" ? loaded.default : loaded;
33
+ const cloned: INestiaConfig = JSON.parse(JSON.stringify(config));
34
+ return assert(cloned);
35
+ });
36
+ }
@@ -1,12 +1,12 @@
1
- import { WorkerServer } from "tgrid/protocols/workers/WorkerServer";
2
-
3
- import { NestiaSdkConfig } from "./NestiaSdkConfig";
4
-
5
- async function main(): Promise<void> {
6
- const worker = new WorkerServer();
7
- await worker.open(NestiaSdkConfig);
8
- }
9
- main().catch((exp) => {
10
- console.log(exp);
11
- process.exit(-1);
12
- });
1
+ import { WorkerServer } from "tgrid/protocols/workers/WorkerServer";
2
+
3
+ import { NestiaSdkConfig } from "./NestiaSdkConfig";
4
+
5
+ async function main(): Promise<void> {
6
+ const worker = new WorkerServer();
7
+ await worker.open(NestiaSdkConfig);
8
+ }
9
+ main().catch((exp) => {
10
+ console.log(exp);
11
+ process.exit(-1);
12
+ });
@@ -1,70 +1,70 @@
1
- #!/usr/bin/env node
2
- import cp from "child_process";
3
- import fs from "fs";
4
- import process from "process";
5
-
6
- import { CommandParser } from "./internal/CommandParser";
7
- import type { NestiaSdkCommand } from "./internal/NestiaSdkCommand";
8
-
9
- const USAGE = `Wrong command has been detected. Use like below:
10
-
11
- npx @nestia/sdk [command] [options?]
12
-
13
- 1. npx @nestia/sdk dependencies --manager (npm|pnpm|yarn)
14
- - npx @nestia/sdk dependencies
15
- - npx @nestia/sdk dependencies --manager pnpm
16
- 2. npx @nestia/sdk init
17
- 3. npx @nestia/sdk sdk
18
- 4. npx @nestia/sdk swagger
19
- 5. npx @nestia/sdk e2e
20
- `;
21
-
22
- function halt(desc: string): never {
23
- console.error(desc);
24
- process.exit(-1);
25
- }
26
-
27
- function dependencies(argv: string[]): void {
28
- // INSTALL DEPENDENCIES
29
- const module = CommandParser.parse(argv).module ?? "npm";
30
- const prefix: string = module === "yarn" ? "yarn add" : `${module} install`;
31
-
32
- for (const lib of ["@nestia/fetcher", "typia"]) {
33
- const command: string = `${prefix} ${lib}`;
34
- cp.execSync(command, { stdio: "inherit" });
35
- }
36
- }
37
-
38
- async function initialize(): Promise<void> {
39
- if (fs.existsSync("nestia.config.ts") === true)
40
- halt(
41
- `Error on nestia.sdk.initialize(): "nestia.config.ts" file already has been configured.`,
42
- );
43
- await fs.promises.copyFile(
44
- `${__dirname}/../../assets/config/nestia.config.ts`,
45
- "nestia.config.ts",
46
- );
47
- }
48
-
49
- async function execute(
50
- closure: (commander: typeof NestiaSdkCommand) => Promise<void>,
51
- ): Promise<void> {
52
- const module = await import("./internal/NestiaSdkCommand");
53
- await closure(module.NestiaSdkCommand);
54
- }
55
-
56
- async function main() {
57
- const type: string | undefined = process.argv[2];
58
- const argv: string[] = process.argv.slice(3);
59
-
60
- if (type === "dependencies") dependencies(argv);
61
- else if (type === "init") await initialize();
62
- else if (type === "sdk") await execute((c) => c.sdk(argv));
63
- else if (type === "swagger") await execute((c) => c.swagger(argv));
64
- else if (type === "e2e") await execute((c) => c.e2e(argv));
65
- else halt(USAGE);
66
- }
67
- main().catch((exp) => {
68
- console.log(exp.message);
69
- process.exit(-1);
70
- });
1
+ #!/usr/bin/env node
2
+ import cp from "child_process";
3
+ import fs from "fs";
4
+ import process from "process";
5
+
6
+ import { CommandParser } from "./internal/CommandParser";
7
+ import type { NestiaSdkCommand } from "./internal/NestiaSdkCommand";
8
+
9
+ const USAGE = `Wrong command has been detected. Use like below:
10
+
11
+ npx @nestia/sdk [command] [options?]
12
+
13
+ 1. npx @nestia/sdk dependencies --manager (npm|pnpm|yarn)
14
+ - npx @nestia/sdk dependencies
15
+ - npx @nestia/sdk dependencies --manager pnpm
16
+ 2. npx @nestia/sdk init
17
+ 3. npx @nestia/sdk sdk
18
+ 4. npx @nestia/sdk swagger
19
+ 5. npx @nestia/sdk e2e
20
+ `;
21
+
22
+ function halt(desc: string): never {
23
+ console.error(desc);
24
+ process.exit(-1);
25
+ }
26
+
27
+ function dependencies(argv: string[]): void {
28
+ // INSTALL DEPENDENCIES
29
+ const module = CommandParser.parse(argv).module ?? "npm";
30
+ const prefix: string = module === "yarn" ? "yarn add" : `${module} install`;
31
+
32
+ for (const lib of ["@nestia/fetcher", "typia"]) {
33
+ const command: string = `${prefix} ${lib}`;
34
+ cp.execSync(command, { stdio: "inherit" });
35
+ }
36
+ }
37
+
38
+ async function initialize(): Promise<void> {
39
+ if (fs.existsSync("nestia.config.ts") === true)
40
+ halt(
41
+ `Error on nestia.sdk.initialize(): "nestia.config.ts" file already has been configured.`,
42
+ );
43
+ await fs.promises.copyFile(
44
+ `${__dirname}/../../assets/config/nestia.config.ts`,
45
+ "nestia.config.ts",
46
+ );
47
+ }
48
+
49
+ async function execute(
50
+ closure: (commander: typeof NestiaSdkCommand) => Promise<void>,
51
+ ): Promise<void> {
52
+ const module = await import("./internal/NestiaSdkCommand");
53
+ await closure(module.NestiaSdkCommand);
54
+ }
55
+
56
+ async function main() {
57
+ const type: string | undefined = process.argv[2];
58
+ const argv: string[] = process.argv.slice(3);
59
+
60
+ if (type === "dependencies") dependencies(argv);
61
+ else if (type === "init") await initialize();
62
+ else if (type === "sdk") await execute((c) => c.sdk(argv));
63
+ else if (type === "swagger") await execute((c) => c.swagger(argv));
64
+ else if (type === "e2e") await execute((c) => c.e2e(argv));
65
+ else halt(USAGE);
66
+ }
67
+ main().catch((exp) => {
68
+ console.log(exp.message);
69
+ process.exit(-1);
70
+ });