@nestia/sdk 1.0.0 → 1.0.2

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 +28 -9
  3. package/lib/analyses/ControllerAnalyzer.js +21 -1
  4. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  5. package/lib/executable/internal/NestiaSdkConfig.js +168 -14
  6. package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
  7. package/lib/executable/sdk.js +16 -16
  8. package/lib/generates/FunctionGenerator.js +35 -15
  9. package/lib/generates/FunctionGenerator.js.map +1 -1
  10. package/lib/generates/SwaggerGenerator.d.ts +1 -1
  11. package/lib/generates/SwaggerGenerator.js +36 -16
  12. package/lib/generates/SwaggerGenerator.js.map +1 -1
  13. package/lib/structures/IRoute.d.ts +8 -0
  14. package/lib/structures/ISwaggerDocument.d.ts +95 -0
  15. package/lib/structures/{ISwagger.js → ISwaggerDocument.js} +1 -1
  16. package/lib/structures/ISwaggerDocument.js.map +1 -0
  17. package/package.json +3 -3
  18. package/src/INestiaConfig.ts +147 -120
  19. package/src/NestiaSdkApplication.ts +183 -183
  20. package/src/analyses/ControllerAnalyzer.ts +223 -203
  21. package/src/analyses/GenericAnalyzer.ts +53 -53
  22. package/src/analyses/ImportAnalyzer.ts +143 -143
  23. package/src/analyses/PathAnalyzer.ts +58 -58
  24. package/src/analyses/ReflectAnalyzer.ts +279 -279
  25. package/src/analyses/SourceFinder.ts +59 -59
  26. package/src/executable/internal/CommandParser.ts +15 -15
  27. package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -18
  28. package/src/executable/internal/NestiaSdkCommand.ts +174 -174
  29. package/src/executable/internal/NestiaSdkConfig.ts +35 -35
  30. package/src/executable/internal/nestia.config.getter.ts +12 -12
  31. package/src/executable/sdk.ts +74 -74
  32. package/src/generates/FileGenerator.ts +156 -156
  33. package/src/generates/FunctionGenerator.ts +322 -287
  34. package/src/generates/SdkGenerator.ts +50 -50
  35. package/src/generates/SwaggerGenerator.ts +422 -393
  36. package/src/index.ts +3 -3
  37. package/src/module.ts +2 -2
  38. package/src/structures/IController.ts +27 -27
  39. package/src/structures/IRoute.ts +33 -29
  40. package/src/structures/ISwaggerDocument.ts +117 -0
  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/ImportDictionary.ts +56 -56
  47. package/src/utils/MapUtil.ts +14 -14
  48. package/src/utils/StripEnums.ts +10 -10
  49. package/lib/structures/ISwagger.d.ts +0 -48
  50. package/lib/structures/ISwagger.js.map +0 -1
  51. package/src/structures/ISwagger.ts +0 -55
@@ -1,156 +1,156 @@
1
- import fs from "fs";
2
- import { HashMap } from "tstl/container/HashMap";
3
-
4
- import { INestiaConfig } from "../INestiaConfig";
5
- import { IRoute } from "../structures/IRoute";
6
- import { ImportDictionary } from "../utils/ImportDictionary";
7
- import { FunctionGenerator } from "./FunctionGenerator";
8
-
9
- export namespace FileGenerator {
10
- /* ---------------------------------------------------------
11
- CONSTRUCTOR
12
- --------------------------------------------------------- */
13
- export async function generate(
14
- config: INestiaConfig,
15
- routeList: IRoute[],
16
- ): Promise<void> {
17
- // CONSTRUCT FOLDER TREE
18
- const root: Directory = new Directory(null, "functional");
19
- for (const route of routeList) emplace(root, route);
20
-
21
- // RELOCATE FOR ONLY ONE CONTROLLER METHOD IN AN URL CASE
22
- relocate(root);
23
-
24
- // ITERATE FILES
25
- await iterate(config, config.output + "/functional", root);
26
- }
27
-
28
- function emplace(directory: Directory, route: IRoute): void {
29
- // SEPARATE IDENTIFIERS
30
- const identifiers: string[] = route.path
31
- .split("/")
32
- .filter((str) => str[0] !== ":" && str.length !== 0)
33
- .map((str) => str.split("-").join("_").split(".").join("_"));
34
-
35
- // OPEN DIRECTORIES
36
- for (const key of identifiers) {
37
- directory = directory.directories.take(
38
- key,
39
- () => new Directory(directory, key),
40
- );
41
- }
42
-
43
- // ADD ROUTE
44
- directory.routes.push(route);
45
- }
46
-
47
- function relocate(directory: Directory): void {
48
- if (
49
- directory.parent !== null &&
50
- directory.directories.empty() &&
51
- directory.routes.length === 1 &&
52
- directory.name === directory.routes[0].name
53
- ) {
54
- directory.parent.routes.push(directory.routes[0]);
55
- directory.parent.directories.erase(directory.name);
56
- } else if (directory.directories.empty() === false)
57
- for (const it of directory.directories) relocate(it.second);
58
- }
59
-
60
- /* ---------------------------------------------------------
61
- FILE ITERATOR
62
- --------------------------------------------------------- */
63
- async function iterate(
64
- config: INestiaConfig,
65
- outDir: string,
66
- directory: Directory,
67
- ): Promise<void> {
68
- // CREATE A NEW DIRECTORY
69
- try {
70
- await fs.promises.mkdir(outDir);
71
- } catch {}
72
-
73
- // ITERATE CHILDREN
74
- const content: string[] = [];
75
- for (const it of directory.directories) {
76
- await iterate(config, `${outDir}/${it.first}`, it.second);
77
- content.push(`export * as ${it.first} from "./${it.first}";`);
78
- }
79
- if (content.length && directory.routes.length) content.push("");
80
-
81
- // ITERATE ROUTES
82
- const importDict: ImportDictionary = new ImportDictionary();
83
- directory.routes.forEach((route, i) => {
84
- for (const tuple of route.imports)
85
- for (const instance of tuple[1])
86
- importDict.emplace(tuple[0], false, instance);
87
-
88
- content.push(FunctionGenerator.generate(config, route));
89
- if (i !== directory.routes.length - 1) content.push("");
90
- });
91
-
92
- // FINALIZE THE CONTENT
93
- if (directory.routes.length !== 0) {
94
- const primitived: boolean =
95
- config.primitive !== false &&
96
- directory.routes.some(
97
- (route) =>
98
- route.output.name !== "void" ||
99
- route.parameters.some(
100
- (param) => param.category !== "param",
101
- ),
102
- );
103
- const asserted: boolean =
104
- config.assert === true &&
105
- directory.routes.some((route) => route.parameters.length !== 0);
106
- const json: boolean =
107
- config.json === true &&
108
- directory.routes.some(
109
- (route) =>
110
- route.method === "POST" ||
111
- route.method === "PUT" ||
112
- route.method === "PATCH",
113
- );
114
-
115
- const fetcher: string[] = ["Fetcher"];
116
- if (primitived) fetcher.push("Primitive");
117
-
118
- const head: string[] = [
119
- `import { ${fetcher.join(", ")} } from "@nestia/fetcher";`,
120
- `import type { IConnection } from "@nestia/fetcher";`,
121
- ];
122
- if (asserted || json) head.push(`import typia from "typia";`);
123
- if (!importDict.empty()) head.push("", importDict.toScript(outDir));
124
-
125
- content.push(...head, "", ...content.splice(0, content.length));
126
- }
127
-
128
- const script: string =
129
- "/**\n" +
130
- " * @packageDocumentation\n" +
131
- ` * @module ${directory.module}\n` +
132
- " * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
133
- " */\n" +
134
- "//================================================================\n" +
135
- content.join("\n");
136
- await fs.promises.writeFile(`${outDir}/index.ts`, script, "utf8");
137
- }
138
- }
139
-
140
- class Directory {
141
- public readonly module: string;
142
- public readonly directories: HashMap<string, Directory>;
143
- public readonly routes: IRoute[];
144
-
145
- public constructor(
146
- readonly parent: Directory | null,
147
- readonly name: string,
148
- ) {
149
- this.directories = new HashMap();
150
- this.routes = [];
151
- this.module =
152
- this.parent !== null
153
- ? `${this.parent.module}.${name}`
154
- : `api.${name}`;
155
- }
156
- }
1
+ import fs from "fs";
2
+ import { HashMap } from "tstl/container/HashMap";
3
+
4
+ import { INestiaConfig } from "../INestiaConfig";
5
+ import { IRoute } from "../structures/IRoute";
6
+ import { ImportDictionary } from "../utils/ImportDictionary";
7
+ import { FunctionGenerator } from "./FunctionGenerator";
8
+
9
+ export namespace FileGenerator {
10
+ /* ---------------------------------------------------------
11
+ CONSTRUCTOR
12
+ --------------------------------------------------------- */
13
+ export async function generate(
14
+ config: INestiaConfig,
15
+ routeList: IRoute[],
16
+ ): Promise<void> {
17
+ // CONSTRUCT FOLDER TREE
18
+ const root: Directory = new Directory(null, "functional");
19
+ for (const route of routeList) emplace(root, route);
20
+
21
+ // RELOCATE FOR ONLY ONE CONTROLLER METHOD IN AN URL CASE
22
+ relocate(root);
23
+
24
+ // ITERATE FILES
25
+ await iterate(config, config.output + "/functional", root);
26
+ }
27
+
28
+ function emplace(directory: Directory, route: IRoute): void {
29
+ // SEPARATE IDENTIFIERS
30
+ const identifiers: string[] = route.path
31
+ .split("/")
32
+ .filter((str) => str[0] !== ":" && str.length !== 0)
33
+ .map((str) => str.split("-").join("_").split(".").join("_"));
34
+
35
+ // OPEN DIRECTORIES
36
+ for (const key of identifiers) {
37
+ directory = directory.directories.take(
38
+ key,
39
+ () => new Directory(directory, key),
40
+ );
41
+ }
42
+
43
+ // ADD ROUTE
44
+ directory.routes.push(route);
45
+ }
46
+
47
+ function relocate(directory: Directory): void {
48
+ if (
49
+ directory.parent !== null &&
50
+ directory.directories.empty() &&
51
+ directory.routes.length === 1 &&
52
+ directory.name === directory.routes[0].name
53
+ ) {
54
+ directory.parent.routes.push(directory.routes[0]);
55
+ directory.parent.directories.erase(directory.name);
56
+ } else if (directory.directories.empty() === false)
57
+ for (const it of directory.directories) relocate(it.second);
58
+ }
59
+
60
+ /* ---------------------------------------------------------
61
+ FILE ITERATOR
62
+ --------------------------------------------------------- */
63
+ async function iterate(
64
+ config: INestiaConfig,
65
+ outDir: string,
66
+ directory: Directory,
67
+ ): Promise<void> {
68
+ // CREATE A NEW DIRECTORY
69
+ try {
70
+ await fs.promises.mkdir(outDir);
71
+ } catch {}
72
+
73
+ // ITERATE CHILDREN
74
+ const content: string[] = [];
75
+ for (const it of directory.directories) {
76
+ await iterate(config, `${outDir}/${it.first}`, it.second);
77
+ content.push(`export * as ${it.first} from "./${it.first}";`);
78
+ }
79
+ if (content.length && directory.routes.length) content.push("");
80
+
81
+ // ITERATE ROUTES
82
+ const importDict: ImportDictionary = new ImportDictionary();
83
+ directory.routes.forEach((route, i) => {
84
+ for (const tuple of route.imports)
85
+ for (const instance of tuple[1])
86
+ importDict.emplace(tuple[0], false, instance);
87
+
88
+ content.push(FunctionGenerator.generate(config, route));
89
+ if (i !== directory.routes.length - 1) content.push("");
90
+ });
91
+
92
+ // FINALIZE THE CONTENT
93
+ if (directory.routes.length !== 0) {
94
+ const primitived: boolean =
95
+ config.primitive !== false &&
96
+ directory.routes.some(
97
+ (route) =>
98
+ route.output.name !== "void" ||
99
+ route.parameters.some(
100
+ (param) => param.category !== "param",
101
+ ),
102
+ );
103
+ const asserted: boolean =
104
+ config.assert === true &&
105
+ directory.routes.some((route) => route.parameters.length !== 0);
106
+ const json: boolean =
107
+ config.json === true &&
108
+ directory.routes.some(
109
+ (route) =>
110
+ route.method === "POST" ||
111
+ route.method === "PUT" ||
112
+ route.method === "PATCH",
113
+ );
114
+
115
+ const fetcher: string[] = ["Fetcher"];
116
+ if (primitived) fetcher.push("Primitive");
117
+
118
+ const head: string[] = [
119
+ `import { ${fetcher.join(", ")} } from "@nestia/fetcher";`,
120
+ `import type { IConnection } from "@nestia/fetcher";`,
121
+ ];
122
+ if (asserted || json) head.push(`import typia from "typia";`);
123
+ if (!importDict.empty()) head.push("", importDict.toScript(outDir));
124
+
125
+ content.push(...head, "", ...content.splice(0, content.length));
126
+ }
127
+
128
+ const script: string =
129
+ "/**\n" +
130
+ " * @packageDocumentation\n" +
131
+ ` * @module ${directory.module}\n` +
132
+ " * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
133
+ " */\n" +
134
+ "//================================================================\n" +
135
+ content.join("\n");
136
+ await fs.promises.writeFile(`${outDir}/index.ts`, script, "utf8");
137
+ }
138
+ }
139
+
140
+ class Directory {
141
+ public readonly module: string;
142
+ public readonly directories: HashMap<string, Directory>;
143
+ public readonly routes: IRoute[];
144
+
145
+ public constructor(
146
+ readonly parent: Directory | null,
147
+ readonly name: string,
148
+ ) {
149
+ this.directories = new HashMap();
150
+ this.routes = [];
151
+ this.module =
152
+ this.parent !== null
153
+ ? `${this.parent.module}.${name}`
154
+ : `api.${name}`;
155
+ }
156
+ }