@nestia/sdk 1.0.4 → 1.0.5

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 (43) hide show
  1. package/README.md +12 -58
  2. package/assets/config/nestia.config.ts +70 -70
  3. package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
  4. package/lib/executable/sdk.js +16 -16
  5. package/lib/generates/FunctionGenerator.js +7 -7
  6. package/lib/generates/FunctionGenerator.js.map +1 -1
  7. package/lib/generates/SwaggerGenerator.js +11 -9
  8. package/lib/generates/SwaggerGenerator.js.map +1 -1
  9. package/lib/index.d.ts +1 -0
  10. package/lib/index.js +4 -0
  11. package/lib/index.js.map +1 -1
  12. package/package.json +2 -1
  13. package/src/INestiaConfig.ts +147 -147
  14. package/src/NestiaSdkApplication.ts +183 -183
  15. package/src/analyses/ControllerAnalyzer.ts +223 -223
  16. package/src/analyses/GenericAnalyzer.ts +53 -53
  17. package/src/analyses/ImportAnalyzer.ts +143 -143
  18. package/src/analyses/PathAnalyzer.ts +58 -58
  19. package/src/analyses/ReflectAnalyzer.ts +287 -287
  20. package/src/analyses/SourceFinder.ts +59 -59
  21. package/src/executable/internal/CommandParser.ts +15 -15
  22. package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -18
  23. package/src/executable/internal/NestiaSdkCommand.ts +174 -174
  24. package/src/executable/internal/NestiaSdkConfig.ts +36 -35
  25. package/src/executable/internal/nestia.config.getter.ts +12 -12
  26. package/src/executable/sdk.ts +74 -74
  27. package/src/generates/FileGenerator.ts +156 -156
  28. package/src/generates/FunctionGenerator.ts +323 -322
  29. package/src/generates/SdkGenerator.ts +50 -50
  30. package/src/generates/SwaggerGenerator.ts +433 -430
  31. package/src/index.ts +4 -3
  32. package/src/module.ts +2 -2
  33. package/src/structures/IController.ts +27 -27
  34. package/src/structures/IRoute.ts +33 -33
  35. package/src/structures/ISwaggerDocument.ts +119 -119
  36. package/src/structures/ITypeTuple.ts +6 -6
  37. package/src/structures/MethodType.ts +11 -11
  38. package/src/structures/ParamCategory.ts +1 -1
  39. package/src/structures/TypeEntry.ts +22 -22
  40. package/src/utils/ArrayUtil.ts +26 -26
  41. package/src/utils/ImportDictionary.ts +56 -56
  42. package/src/utils/MapUtil.ts +14 -14
  43. package/src/utils/StripEnums.ts +10 -10
@@ -1,59 +1,59 @@
1
- import fs from "fs";
2
- import glob from "glob";
3
- import path from "path";
4
-
5
- import { INestiaConfig } from "../INestiaConfig";
6
-
7
- export namespace SourceFinder {
8
- export async function find(input: INestiaConfig.IInput): Promise<string[]> {
9
- const dict: Set<string> = new Set();
10
-
11
- await decode(input.include, (str) => dict.add(str));
12
- if (input.exclude)
13
- await decode(input.exclude, (str) => dict.delete(str));
14
-
15
- return [...dict];
16
- }
17
-
18
- async function decode(
19
- input: string[],
20
- closure: (location: string) => void,
21
- ): Promise<void> {
22
- for (const pattern of input) {
23
- for (const location of await _Glob(path.resolve(pattern))) {
24
- const stats: fs.Stats = await fs.promises.stat(location);
25
- if (stats.isDirectory() === true)
26
- await iterate(closure, location);
27
- else if (stats.isFile() && _Is_ts_file(location))
28
- closure(location);
29
- }
30
- }
31
- }
32
-
33
- async function iterate(
34
- closure: (location: string) => void,
35
- location: string,
36
- ): Promise<void> {
37
- const directory: string[] = await fs.promises.readdir(location);
38
- for (const file of directory) {
39
- const next: string = path.resolve(`${location}/${file}`);
40
- const stats: fs.Stats = await fs.promises.stat(next);
41
-
42
- if (stats.isDirectory() === true) await iterate(closure, next);
43
- else if (stats.isFile() && _Is_ts_file(file)) closure(next);
44
- }
45
- }
46
-
47
- function _Glob(pattern: string): Promise<string[]> {
48
- return new Promise((resolve, reject) => {
49
- glob(pattern, (err, matches) => {
50
- if (err) reject(err);
51
- else resolve(matches.map((str) => path.resolve(str)));
52
- });
53
- });
54
- }
55
-
56
- function _Is_ts_file(file: string): boolean {
57
- return file.substr(-3) === ".ts" && file.substr(-5) !== ".d.ts";
58
- }
59
- }
1
+ import fs from "fs";
2
+ import glob from "glob";
3
+ import path from "path";
4
+
5
+ import { INestiaConfig } from "../INestiaConfig";
6
+
7
+ export namespace SourceFinder {
8
+ export async function find(input: INestiaConfig.IInput): Promise<string[]> {
9
+ const dict: Set<string> = new Set();
10
+
11
+ await decode(input.include, (str) => dict.add(str));
12
+ if (input.exclude)
13
+ await decode(input.exclude, (str) => dict.delete(str));
14
+
15
+ return [...dict];
16
+ }
17
+
18
+ async function decode(
19
+ input: string[],
20
+ closure: (location: string) => void,
21
+ ): Promise<void> {
22
+ for (const pattern of input) {
23
+ for (const location of await _Glob(path.resolve(pattern))) {
24
+ const stats: fs.Stats = await fs.promises.stat(location);
25
+ if (stats.isDirectory() === true)
26
+ await iterate(closure, location);
27
+ else if (stats.isFile() && _Is_ts_file(location))
28
+ closure(location);
29
+ }
30
+ }
31
+ }
32
+
33
+ async function iterate(
34
+ closure: (location: string) => void,
35
+ location: string,
36
+ ): Promise<void> {
37
+ const directory: string[] = await fs.promises.readdir(location);
38
+ for (const file of directory) {
39
+ const next: string = path.resolve(`${location}/${file}`);
40
+ const stats: fs.Stats = await fs.promises.stat(next);
41
+
42
+ if (stats.isDirectory() === true) await iterate(closure, next);
43
+ else if (stats.isFile() && _Is_ts_file(file)) closure(next);
44
+ }
45
+ }
46
+
47
+ function _Glob(pattern: string): Promise<string[]> {
48
+ return new Promise((resolve, reject) => {
49
+ glob(pattern, (err, matches) => {
50
+ if (err) reject(err);
51
+ else resolve(matches.map((str) => path.resolve(str)));
52
+ });
53
+ });
54
+ }
55
+
56
+ function _Is_ts_file(file: string): boolean {
57
+ return file.substr(-3) === ".ts" && file.substr(-5) !== ".d.ts";
58
+ }
59
+ }
@@ -1,15 +1,15 @@
1
- export namespace CommandParser {
2
- export function parse(argList: string[]): Record<string, string> {
3
- const output: Record<string, string> = {};
4
- argList.forEach((arg, i) => {
5
- if (arg.startsWith("--") === false) return;
6
-
7
- const key = arg.slice(2);
8
- const value: string | undefined = argList[i + 1];
9
- if (value === undefined || value.startsWith("--")) return;
10
-
11
- output[key] = value;
12
- });
13
- return output;
14
- }
15
- }
1
+ export namespace CommandParser {
2
+ export function parse(argList: string[]): Record<string, string> {
3
+ const output: Record<string, string> = {};
4
+ argList.forEach((arg, i) => {
5
+ if (arg.startsWith("--") === false) return;
6
+
7
+ const key = arg.slice(2);
8
+ const value: string | undefined = argList[i + 1];
9
+ if (value === undefined || value.startsWith("--")) return;
10
+
11
+ output[key] = value;
12
+ });
13
+ return output;
14
+ }
15
+ }
@@ -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,174 +1,174 @@
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
- }
15
-
16
- interface IOutput {
17
- assign: (config: INestiaConfig, output: string) => void;
18
- validate: (config: INestiaConfig) => boolean;
19
- location: (config: INestiaConfig) => string;
20
- }
21
-
22
- export namespace NestiaSdkCommand {
23
- export function sdk(
24
- elements: string[],
25
- pure: boolean = true,
26
- ): Promise<void> {
27
- return main(
28
- (app) => app.sdk(),
29
- {
30
- assign: (config, output) => (config.output = output),
31
- validate: (config) => !!config.output,
32
- location: (config) => config.output!,
33
- },
34
- elements,
35
- pure,
36
- );
37
- }
38
-
39
- export function swagger(
40
- elements: string[],
41
- pure: boolean = true,
42
- ): Promise<void> {
43
- return main(
44
- (app) => app.swagger(),
45
- {
46
- assign: (config, output) => {
47
- if (!config.swagger) config.swagger = { output };
48
- else config.swagger.output = output;
49
- },
50
- validate: (config) =>
51
- !!config.swagger && !!config.swagger.output,
52
- location: (config) => config.swagger!.output!,
53
- },
54
- elements,
55
- pure,
56
- );
57
- }
58
-
59
- async function main(
60
- task: (app: NestiaSdkApplication) => Promise<void>,
61
- output: IOutput,
62
- elements: string[],
63
- pure: boolean,
64
- ): Promise<void> {
65
- if (pure === false)
66
- cli.setArgv([
67
- process.argv[0],
68
- process.argv[1],
69
- "nestia",
70
- ...elements,
71
- ]);
72
- const command: ICommand = cli.parse({
73
- exclude: ["e", "Something to exclude", "string", null],
74
- out: ["o", "Output path of the SDK files", "string", null],
75
- });
76
-
77
- const inputs: string[] = [];
78
- for (const arg of elements) {
79
- if (arg[0] === "-") break;
80
- inputs.push(arg);
81
- }
82
- await generate(task, inputs, command, output);
83
- }
84
-
85
- async function generate(
86
- task: (app: NestiaSdkApplication) => Promise<void>,
87
- include: string[],
88
- command: ICommand,
89
- output: IOutput,
90
- ): Promise<void> {
91
- // CONFIGURATION
92
- const config: INestiaConfig =
93
- (await get_nestia_config(output.validate)) ??
94
- parse_cli(include, command, output);
95
-
96
- const options = await get_typescript_options();
97
-
98
- config.compilerOptions = {
99
- ...options,
100
- ...(config.compilerOptions || {}),
101
- };
102
-
103
- // CALL THE APP.GENERATE()
104
- const app: NestiaSdkApplication = new NestiaSdkApplication(config);
105
- await task(app);
106
- }
107
-
108
- async function get_typescript_options(): Promise<ts.CompilerOptions | null> {
109
- const configFileName = ts.findConfigFile(
110
- process.cwd(),
111
- ts.sys.fileExists,
112
- "tsconfig.json",
113
- );
114
-
115
- if (!configFileName) return null;
116
-
117
- const { tsconfig } = await parseNative(configFileName);
118
-
119
- const configFileText = JSON.stringify(tsconfig);
120
-
121
- const { config } = ts.parseConfigFileTextToJson(
122
- configFileName,
123
- configFileText,
124
- );
125
-
126
- const configParseResult = ts.parseJsonConfigFileContent(
127
- config,
128
- ts.sys,
129
- path.dirname(configFileName),
130
- );
131
-
132
- const { moduleResolution, ...result } =
133
- configParseResult.raw.compilerOptions;
134
- return result;
135
- }
136
-
137
- async function get_nestia_config(
138
- validate: (config: INestiaConfig) => boolean,
139
- ): Promise<INestiaConfig | null> {
140
- const connector = new WorkerConnector(null, null, "process");
141
- await connector.connect(`${__dirname}/nestia.config.getter.js`);
142
-
143
- const driver = await connector.getDriver<typeof NestiaSdkConfig>();
144
- const config: INestiaConfig | null = await driver.get();
145
- await connector.close();
146
-
147
- if (config !== null && validate(config) === false)
148
- throw new Error(
149
- `Error on NestiaCommand.main(): output path is not specified in the "nestia.config.ts".`,
150
- );
151
-
152
- return config;
153
- }
154
-
155
- function parse_cli(
156
- include: string[],
157
- command: ICommand,
158
- output: IOutput,
159
- ): INestiaConfig {
160
- if (command.out === null)
161
- throw new Error(
162
- `Error on NestiaCommand.main(): output directory is not specified. Add the "--out <output_directory>" option.`,
163
- );
164
-
165
- const config: INestiaConfig = {
166
- input: {
167
- include,
168
- exclude: command.exclude ? [command.exclude] : undefined,
169
- },
170
- };
171
- output.assign(config, command.out);
172
- return config;
173
- }
174
- }
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
+ }
15
+
16
+ interface IOutput {
17
+ assign: (config: INestiaConfig, output: string) => void;
18
+ validate: (config: INestiaConfig) => boolean;
19
+ location: (config: INestiaConfig) => string;
20
+ }
21
+
22
+ export namespace NestiaSdkCommand {
23
+ export function sdk(
24
+ elements: string[],
25
+ pure: boolean = true,
26
+ ): Promise<void> {
27
+ return main(
28
+ (app) => app.sdk(),
29
+ {
30
+ assign: (config, output) => (config.output = output),
31
+ validate: (config) => !!config.output,
32
+ location: (config) => config.output!,
33
+ },
34
+ elements,
35
+ pure,
36
+ );
37
+ }
38
+
39
+ export function swagger(
40
+ elements: string[],
41
+ pure: boolean = true,
42
+ ): Promise<void> {
43
+ return main(
44
+ (app) => app.swagger(),
45
+ {
46
+ assign: (config, output) => {
47
+ if (!config.swagger) config.swagger = { output };
48
+ else config.swagger.output = output;
49
+ },
50
+ validate: (config) =>
51
+ !!config.swagger && !!config.swagger.output,
52
+ location: (config) => config.swagger!.output!,
53
+ },
54
+ elements,
55
+ pure,
56
+ );
57
+ }
58
+
59
+ async function main(
60
+ task: (app: NestiaSdkApplication) => Promise<void>,
61
+ output: IOutput,
62
+ elements: string[],
63
+ pure: boolean,
64
+ ): Promise<void> {
65
+ if (pure === false)
66
+ cli.setArgv([
67
+ process.argv[0],
68
+ process.argv[1],
69
+ "nestia",
70
+ ...elements,
71
+ ]);
72
+ const command: ICommand = cli.parse({
73
+ exclude: ["e", "Something to exclude", "string", null],
74
+ out: ["o", "Output path of the SDK files", "string", null],
75
+ });
76
+
77
+ const inputs: string[] = [];
78
+ for (const arg of elements) {
79
+ if (arg[0] === "-") break;
80
+ inputs.push(arg);
81
+ }
82
+ await generate(task, inputs, command, output);
83
+ }
84
+
85
+ async function generate(
86
+ task: (app: NestiaSdkApplication) => Promise<void>,
87
+ include: string[],
88
+ command: ICommand,
89
+ output: IOutput,
90
+ ): Promise<void> {
91
+ // CONFIGURATION
92
+ const config: INestiaConfig =
93
+ (await get_nestia_config(output.validate)) ??
94
+ parse_cli(include, command, output);
95
+
96
+ const options = await get_typescript_options();
97
+
98
+ config.compilerOptions = {
99
+ ...options,
100
+ ...(config.compilerOptions || {}),
101
+ };
102
+
103
+ // CALL THE APP.GENERATE()
104
+ const app: NestiaSdkApplication = new NestiaSdkApplication(config);
105
+ await task(app);
106
+ }
107
+
108
+ async function get_typescript_options(): Promise<ts.CompilerOptions | null> {
109
+ const configFileName = ts.findConfigFile(
110
+ process.cwd(),
111
+ ts.sys.fileExists,
112
+ "tsconfig.json",
113
+ );
114
+
115
+ if (!configFileName) return null;
116
+
117
+ const { tsconfig } = await parseNative(configFileName);
118
+
119
+ const configFileText = JSON.stringify(tsconfig);
120
+
121
+ const { config } = ts.parseConfigFileTextToJson(
122
+ configFileName,
123
+ configFileText,
124
+ );
125
+
126
+ const configParseResult = ts.parseJsonConfigFileContent(
127
+ config,
128
+ ts.sys,
129
+ path.dirname(configFileName),
130
+ );
131
+
132
+ const { moduleResolution, ...result } =
133
+ configParseResult.raw.compilerOptions;
134
+ return result;
135
+ }
136
+
137
+ async function get_nestia_config(
138
+ validate: (config: INestiaConfig) => boolean,
139
+ ): Promise<INestiaConfig | null> {
140
+ const connector = new WorkerConnector(null, null, "process");
141
+ await connector.connect(`${__dirname}/nestia.config.getter.js`);
142
+
143
+ const driver = await connector.getDriver<typeof NestiaSdkConfig>();
144
+ const config: INestiaConfig | null = await driver.get();
145
+ await connector.close();
146
+
147
+ if (config !== null && validate(config) === false)
148
+ throw new Error(
149
+ `Error on NestiaCommand.main(): output path is not specified in the "nestia.config.ts".`,
150
+ );
151
+
152
+ return config;
153
+ }
154
+
155
+ function parse_cli(
156
+ include: string[],
157
+ command: ICommand,
158
+ output: IOutput,
159
+ ): INestiaConfig {
160
+ if (command.out === null)
161
+ throw new Error(
162
+ `Error on NestiaCommand.main(): output directory is not specified. Add the "--out <output_directory>" option.`,
163
+ );
164
+
165
+ const config: INestiaConfig = {
166
+ input: {
167
+ include,
168
+ exclude: command.exclude ? [command.exclude] : undefined,
169
+ },
170
+ };
171
+ output.assign(config, command.out);
172
+ return config;
173
+ }
174
+ }
@@ -1,35 +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
- import { assert } from "typia";
6
-
7
- import { INestiaConfig } from "../../INestiaConfig";
8
-
9
- export namespace NestiaSdkConfig {
10
- export function get(): Promise<INestiaConfig | null> {
11
- return singleton.get();
12
- }
13
-
14
- const singleton = new Singleton(async () => {
15
- if (fs.existsSync("nestia.config.ts") === false) return null;
16
-
17
- runner.register({
18
- emit: false,
19
- compilerOptions: {
20
- module: "CommonJS",
21
- noEmit: true,
22
- },
23
- });
24
-
25
- const loaded: INestiaConfig & { default?: INestiaConfig } =
26
- await import(path.resolve("nestia.config.ts"));
27
- if (typeof loaded !== "object")
28
- throw new Error("Error on NestiaConfig.get(): failed to load data");
29
-
30
- const config: INestiaConfig =
31
- typeof loaded.default === "object" ? loaded.default : loaded;
32
- const cloned: INestiaConfig = JSON.parse(JSON.stringify(config));
33
- return assert(cloned);
34
- });
35
- }
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
+ });