@nestia/sdk 1.0.4 → 1.0.6

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 (42) 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.map +1 -1
  6. package/lib/generates/SwaggerGenerator.js +3 -2
  7. package/lib/generates/SwaggerGenerator.js.map +1 -1
  8. package/lib/index.d.ts +1 -0
  9. package/lib/index.js +4 -0
  10. package/lib/index.js.map +1 -1
  11. package/package.json +2 -1
  12. package/src/INestiaConfig.ts +147 -147
  13. package/src/NestiaSdkApplication.ts +183 -183
  14. package/src/analyses/ControllerAnalyzer.ts +223 -223
  15. package/src/analyses/GenericAnalyzer.ts +53 -53
  16. package/src/analyses/ImportAnalyzer.ts +143 -143
  17. package/src/analyses/PathAnalyzer.ts +58 -58
  18. package/src/analyses/ReflectAnalyzer.ts +287 -287
  19. package/src/analyses/SourceFinder.ts +59 -59
  20. package/src/executable/internal/CommandParser.ts +15 -15
  21. package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -18
  22. package/src/executable/internal/NestiaSdkCommand.ts +174 -174
  23. package/src/executable/internal/NestiaSdkConfig.ts +1 -0
  24. package/src/executable/internal/nestia.config.getter.ts +12 -12
  25. package/src/executable/sdk.ts +74 -74
  26. package/src/generates/FileGenerator.ts +156 -156
  27. package/src/generates/FunctionGenerator.ts +1 -0
  28. package/src/generates/SdkGenerator.ts +50 -50
  29. package/src/generates/SwaggerGenerator.ts +4 -1
  30. package/src/index.ts +1 -0
  31. package/src/module.ts +2 -2
  32. package/src/structures/IController.ts +27 -27
  33. package/src/structures/IRoute.ts +33 -33
  34. package/src/structures/ISwaggerDocument.ts +119 -119
  35. package/src/structures/ITypeTuple.ts +6 -6
  36. package/src/structures/MethodType.ts +11 -11
  37. package/src/structures/ParamCategory.ts +1 -1
  38. package/src/structures/TypeEntry.ts +22 -22
  39. package/src/utils/ArrayUtil.ts +26 -26
  40. package/src/utils/ImportDictionary.ts +56 -56
  41. package/src/utils/MapUtil.ts +14 -14
  42. 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
+ }
@@ -2,6 +2,7 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import * as runner from "ts-node";
4
4
  import { Singleton } from "tstl/thread/Singleton";
5
+
5
6
  import { assert } from "typia";
6
7
 
7
8
  import { INestiaConfig } from "../../INestiaConfig";
@@ -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
+ });