nestia 2.0.6 → 2.0.7-dev.20220414

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 (121) hide show
  1. package/{src/IConfiguration.ts → bin/IConfiguration.d.ts} +5 -8
  2. package/bin/IConfiguration.d.ts.map +1 -0
  3. package/bin/IConfiguration.js +3 -0
  4. package/bin/NestiaApplication.d.ts +10 -0
  5. package/bin/NestiaApplication.d.ts.map +1 -0
  6. package/bin/NestiaApplication.js +281 -0
  7. package/bin/analyses/ControllerAnalyzer.d.ts +7 -0
  8. package/bin/analyses/ControllerAnalyzer.d.ts.map +1 -0
  9. package/bin/analyses/ControllerAnalyzer.js +186 -0
  10. package/bin/analyses/GenericAnalyzer.d.ts +6 -0
  11. package/bin/analyses/GenericAnalyzer.d.ts.map +1 -0
  12. package/bin/analyses/GenericAnalyzer.js +100 -0
  13. package/bin/analyses/ImportAnalyzer.d.ts +13 -0
  14. package/bin/analyses/ImportAnalyzer.d.ts.map +1 -0
  15. package/bin/analyses/ImportAnalyzer.js +82 -0
  16. package/bin/analyses/ReflectAnalyzer.d.ts +5 -0
  17. package/bin/analyses/ReflectAnalyzer.d.ts.map +1 -0
  18. package/bin/analyses/ReflectAnalyzer.js +307 -0
  19. package/bin/analyses/SourceFinder.d.ts +5 -0
  20. package/bin/analyses/SourceFinder.d.ts.map +1 -0
  21. package/bin/analyses/SourceFinder.js +260 -0
  22. package/bin/bundle/HttpError.d.ts +2 -0
  23. package/bin/bundle/HttpError.d.ts.map +1 -0
  24. package/bin/bundle/HttpError.js +6 -0
  25. package/bin/bundle/IConnection.d.ts +2 -0
  26. package/bin/bundle/IConnection.d.ts.map +1 -0
  27. package/bin/bundle/IConnection.js +3 -0
  28. package/bin/bundle/Primitive.d.ts +2 -0
  29. package/bin/bundle/Primitive.d.ts.map +1 -0
  30. package/bin/bundle/Primitive.js +6 -0
  31. package/bin/bundle/__internal/AesPkcs5.d.ts +2 -0
  32. package/bin/bundle/__internal/AesPkcs5.d.ts.map +1 -0
  33. package/bin/bundle/__internal/AesPkcs5.js +6 -0
  34. package/bin/bundle/__internal/Fetcher.d.ts +2 -0
  35. package/bin/bundle/__internal/Fetcher.d.ts.map +1 -0
  36. package/bin/bundle/__internal/Fetcher.js +6 -0
  37. package/bin/executable/internal/CompilerOptions.d.ts +13 -0
  38. package/bin/executable/internal/CompilerOptions.d.ts.map +1 -0
  39. package/bin/executable/internal/CompilerOptions.js +132 -0
  40. package/bin/executable/internal/NestiaConfig.d.ts +5 -0
  41. package/bin/executable/internal/NestiaConfig.d.ts.map +1 -0
  42. package/bin/executable/internal/NestiaConfig.js +196 -0
  43. package/bin/executable/internal/nestia.config.getter.d.ts +2 -0
  44. package/bin/executable/internal/nestia.config.getter.d.ts.map +1 -0
  45. package/bin/executable/internal/nestia.config.getter.js +60 -0
  46. package/bin/executable/nestia.d.ts +3 -0
  47. package/bin/executable/nestia.d.ts.map +1 -0
  48. package/bin/executable/nestia.js +136 -0
  49. package/bin/executable/sdk.d.ts +2 -0
  50. package/bin/executable/sdk.d.ts.map +1 -0
  51. package/bin/executable/sdk.js +206 -0
  52. package/bin/generates/FileGenerator.d.ts +6 -0
  53. package/bin/generates/FileGenerator.d.ts.map +1 -0
  54. package/bin/generates/FileGenerator.js +302 -0
  55. package/bin/generates/FunctionGenerator.d.ts +5 -0
  56. package/bin/generates/FunctionGenerator.d.ts.map +1 -0
  57. package/bin/generates/FunctionGenerator.js +207 -0
  58. package/bin/generates/SdkGenerator.d.ts +6 -0
  59. package/bin/generates/SdkGenerator.d.ts.map +1 -0
  60. package/bin/generates/SdkGenerator.js +147 -0
  61. package/bin/index.d.ts +3 -0
  62. package/bin/index.d.ts.map +1 -0
  63. package/bin/index.js +28 -0
  64. package/bin/module.d.ts +3 -0
  65. package/bin/module.d.ts.map +1 -0
  66. package/bin/module.js +19 -0
  67. package/{src/structures/IController.ts → bin/structures/IController.d.ts} +6 -13
  68. package/bin/structures/IController.d.ts.map +1 -0
  69. package/bin/structures/IController.js +3 -0
  70. package/{src/structures/IRoute.ts → bin/structures/IRoute.d.ts} +5 -11
  71. package/bin/structures/IRoute.d.ts.map +1 -0
  72. package/bin/structures/IRoute.js +3 -0
  73. package/bin/structures/MethodType.d.ts +5 -0
  74. package/bin/structures/MethodType.d.ts.map +1 -0
  75. package/bin/structures/MethodType.js +8 -0
  76. package/bin/structures/ParamCategory.d.ts +2 -0
  77. package/bin/structures/ParamCategory.d.ts.map +1 -0
  78. package/bin/structures/ParamCategory.js +3 -0
  79. package/bin/utils/ArrayUtil.d.ts +6 -0
  80. package/bin/utils/ArrayUtil.d.ts.map +1 -0
  81. package/bin/utils/ArrayUtil.js +144 -0
  82. package/bin/utils/DirectoryUtil.d.ts +6 -0
  83. package/bin/utils/DirectoryUtil.d.ts.map +1 -0
  84. package/bin/utils/DirectoryUtil.js +190 -0
  85. package/bin/utils/ImportDictionary.d.ts +7 -0
  86. package/bin/utils/ImportDictionary.d.ts.map +1 -0
  87. package/bin/utils/ImportDictionary.js +85 -0
  88. package/bin/utils/StringUtil.d.ts +4 -0
  89. package/bin/utils/StringUtil.d.ts.map +1 -0
  90. package/bin/utils/StringUtil.js +13 -0
  91. package/bin/utils/stripJsonComments.d.ts +4 -0
  92. package/bin/utils/stripJsonComments.d.ts.map +1 -0
  93. package/bin/utils/stripJsonComments.js +76 -0
  94. package/package.json +14 -10
  95. package/tsconfig.json +8 -7
  96. package/src/NestiaApplication.ts +0 -96
  97. package/src/analyses/ControllerAnalyzer.ts +0 -154
  98. package/src/analyses/GenericAnalyzer.ts +0 -52
  99. package/src/analyses/ImportAnalyzer.ts +0 -93
  100. package/src/analyses/ReflectAnalyzer.ts +0 -221
  101. package/src/analyses/SourceFinder.ts +0 -73
  102. package/src/bin/nestia.ts +0 -59
  103. package/src/bundle/HttpError.ts +0 -1
  104. package/src/bundle/IConnection.ts +0 -1
  105. package/src/bundle/Primitive.ts +0 -1
  106. package/src/bundle/__internal/AesPkcs5.ts +0 -1
  107. package/src/bundle/__internal/Fetcher.ts +0 -1
  108. package/src/executable/sdk.ts +0 -84
  109. package/src/generates/FileGenerator.ts +0 -150
  110. package/src/generates/FunctionGenerator.ts +0 -201
  111. package/src/generates/SdkGenerator.ts +0 -39
  112. package/src/internal/NestiaConfig.ts +0 -36
  113. package/src/internal/TsConfig.ts +0 -123
  114. package/src/internal/tsconfig.default.json +0 -81
  115. package/src/structures/MethodType.ts +0 -6
  116. package/src/structures/ParamCategory.ts +0 -1
  117. package/src/utils/ArrayUtil.ts +0 -26
  118. package/src/utils/DirectoryUtil.ts +0 -48
  119. package/src/utils/ImportDictionary.ts +0 -44
  120. package/src/utils/StringUtil.ts +0 -10
  121. package/src/utils/stripJsonComments.ts +0 -79
package/src/bin/nestia.ts DELETED
@@ -1,59 +0,0 @@
1
- #!/usr/bin/env ts-node
2
-
3
- import * as cp from "child_process";
4
- import * as path from "path";
5
- import * as process from "process";
6
-
7
- import { TsConfig } from "../internal/TsConfig";
8
-
9
- function install(): void
10
- {
11
- // INSTALL DEPENDENCIES
12
- for (const lib of ["nestia-fetcher", "typescript-is"])
13
- {
14
- const command: string = `npm install ${lib}`;
15
- cp.execSync(command, { stdio: "inherit" });
16
- }
17
- }
18
-
19
- async function sdk(): Promise<void>
20
- {
21
- // PREPARE TSCONFIG
22
- await TsConfig.fulfill();
23
-
24
- // CONSTRUCT COMMAND
25
- const parameters: string[] = [
26
- `npx ts-node`,
27
- `"${path.relative(process.cwd(), `${__dirname}/../executable/sdk`)}"`,
28
- ...process.argv.slice(3)
29
- ];
30
- const command: string = parameters.join(" ");
31
-
32
- // EXECUTE THE COMMAND, BUT IGNORE WARNINGS
33
- cp.execSync
34
- (
35
- command,
36
- {
37
- stdio: "inherit",
38
- env: {
39
- ...process.env,
40
- "TS_NODE_COMPILER": "ttypescript",
41
- "NODE_NO_WARNINGS": "1"
42
- }
43
- }
44
- );
45
- }
46
- async function main()
47
- {
48
- if (process.argv[2] === "install")
49
- await install();
50
- else if (process.argv[2] === "sdk")
51
- await sdk();
52
- else
53
- throw new Error(`nestia supports only two commands; install and sdk, however you've typed the "${process.argv[2]}"`);
54
- }
55
- main().catch(exp =>
56
- {
57
- console.log(exp.message);
58
- process.exit(-1);
59
- });
@@ -1 +0,0 @@
1
- export { HttpError } from "nestia-fetcher";
@@ -1 +0,0 @@
1
- export { IConnection } from "nestia-fetcher";
@@ -1 +0,0 @@
1
- export { Primitive } from "nestia-fetcher";
@@ -1 +0,0 @@
1
- export { AesPkcs5 } from "nestia-fetcher";
@@ -1 +0,0 @@
1
- export { Fetcher } from "nestia-fetcher";
@@ -1,84 +0,0 @@
1
- import * as cli from "cli";
2
- import * as fs from "fs";
3
- import * as path from "path";
4
- import * as tsc from "typescript";
5
-
6
- import { IConfiguration } from "../IConfiguration";
7
- import { NestiaApplication } from "../NestiaApplication";
8
- import { stripJsonComments } from "../utils/stripJsonComments";
9
- import { NestiaConfig } from "../internal/NestiaConfig";
10
-
11
- interface ICommand
12
- {
13
- exclude: string | null;
14
- out: string | null;
15
- }
16
-
17
- async function sdk(include: string[], command: ICommand): Promise<void>
18
- {
19
- // CONFIGURATION
20
- let config: IConfiguration | null = await NestiaConfig.get();
21
- if (config === null)
22
- {
23
- if (command.out === null)
24
- throw new Error(`Output directory is not specified. Add the "--out <output_directory>" option.`);
25
- config = {
26
- input: {
27
- include,
28
- exclude: command.exclude
29
- ? [command.exclude]
30
- : undefined
31
- },
32
- output: command.out
33
- };
34
- }
35
-
36
- // VALIDATE OUTPUT DIRECTORY
37
- const parentPath: string = path.resolve(config.output + "/..");
38
- const parentStats: fs.Stats = await fs.promises.stat(parentPath);
39
-
40
- if (parentStats.isDirectory() === false)
41
- throw new Error(`Unable to find parent directory of the output path: "${parentPath}".`);
42
-
43
- // GENERATION
44
- if (fs.existsSync("tsconfig.json") === true)
45
- {
46
- const content: string = await fs.promises.readFile("tsconfig.json", "utf8");
47
- const options: tsc.CompilerOptions = JSON.parse(stripJsonComments(content)).compilerOptions;
48
-
49
- config.compilerOptions = {
50
- ...options,
51
- ...(config.compilerOptions || {})
52
- };
53
- }
54
-
55
- // CALL THE APP.GENERATE()
56
- const app: NestiaApplication = new NestiaApplication(config);
57
- await app.generate();
58
- }
59
-
60
- async function main(): Promise<void>
61
- {
62
- const command: ICommand = cli.parse({
63
- exclude: ["e", "Something to exclude", "string", null],
64
- out: ["o", "Output path of the SDK files", "string", null],
65
- });
66
-
67
- try
68
- {
69
- const inputs: string[] = [];
70
- for (const arg of process.argv.slice(2))
71
- {
72
- if (arg[0] === "-")
73
- break;
74
- inputs.push(arg);
75
- }
76
- await sdk(inputs, command);
77
- }
78
- catch (exp)
79
- {
80
- console.log(exp);
81
- process.exit(-1);
82
- }
83
- }
84
- main();
@@ -1,150 +0,0 @@
1
- import * as fs from "fs";
2
- import { HashMap } from "tstl/container/HashMap";
3
- import { IConfiguration } from "../IConfiguration";
4
-
5
- import { IRoute } from "../structures/IRoute";
6
- import { ImportDictionary } from "../utils/ImportDictionary";
7
- import { FunctionGenerator } from "./FunctionGenerator";
8
-
9
- export namespace FileGenerator
10
- {
11
- /* ---------------------------------------------------------
12
- CONSTRUCTOR
13
- --------------------------------------------------------- */
14
- export async function generate(config: IConfiguration, routeList: IRoute[]): Promise<void>
15
- {
16
- // CONSTRUCT FOLDER TREE
17
- const root: Directory = new Directory(null, "functional");
18
- for (const route of routeList)
19
- 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.assert, config.output + "/functional", root);
26
- }
27
-
28
- function emplace(directory: Directory, route: IRoute): void
29
- {
30
- // SEPARATE IDENTIFIERS
31
- const identifiers: string[] = route.path
32
- .split("/")
33
- .filter(str => str[0] !== ":" && str.length !== 0)
34
- .map(str => str.split("-").join("_").split(".").join("_"));
35
-
36
- for (const key of identifiers)
37
- {
38
- // EMPLACE IF REQUIRED
39
- let it: HashMap.Iterator<string, Directory> = directory.directories.find(key);
40
- if (it.equals(directory.directories.end()) === true)
41
- it = directory.directories.emplace(key, new Directory(directory, key)).first;
42
-
43
- // FOR THE NEXT STEP
44
- directory = it.second;
45
- }
46
- directory.routes.push(route);
47
- }
48
-
49
- function relocate(directory: Directory): void
50
- {
51
- if (directory.parent !== null
52
- && directory.directories.empty()
53
- && directory.routes.length === 1
54
- && directory.name === directory.routes[0].name)
55
- {
56
- directory.parent.routes.push(directory.routes[0]);
57
- directory.parent.directories.erase(directory.name);
58
- }
59
- else if (directory.directories.empty() === false)
60
- for (const it of directory.directories)
61
- relocate(it.second);
62
- }
63
-
64
- /* ---------------------------------------------------------
65
- FILE ITERATOR
66
- --------------------------------------------------------- */
67
- async function iterate
68
- (
69
- assert: boolean,
70
- outDir: string,
71
- directory: Directory
72
- ): Promise<void>
73
- {
74
- // CREATE A NEW DIRECTORY
75
- try
76
- {
77
- await fs.promises.mkdir(outDir);
78
- }
79
- catch {}
80
-
81
- // ITERATE CHILDREN
82
- let content: string = "";
83
- for (const it of directory.directories)
84
- {
85
- await iterate(assert, `${outDir}/${it.first}`, it.second);
86
- content += `export * as ${it.first} from "./${it.first}";\n`;
87
- }
88
- content += "\n";
89
-
90
- // ITERATE ROUTES
91
- const importDict: ImportDictionary = new ImportDictionary();
92
- for (const route of directory.routes)
93
- {
94
- for (const tuple of route.imports)
95
- for (const instance of tuple[1])
96
- importDict.emplace(tuple[0], false, instance);
97
- content += FunctionGenerator.generate(assert, route) + "\n\n";
98
- }
99
-
100
- // FINALIZE THE CONTENT
101
- if (directory.routes.length !== 0)
102
- {
103
- const primitived: boolean = directory.routes.some(route => route.output !== "void"
104
- || route.parameters.some(param => param.category !== "param")
105
- );
106
- const asserted: boolean = assert
107
- && directory.routes.some(route => route.parameters.length !== 0);
108
-
109
- const fetcher: string[] = ["Fetcher"];
110
- if (primitived)
111
- fetcher.push("Primitive");
112
-
113
- content = ""
114
- + `import { ${fetcher.join(", ")} } from "nestia-fetcher";\n`
115
- + `import type { IConnection } from "nestia-fetcher";\n`
116
- + (asserted ? `import { assertType } from "typescript-is";\n` : "")
117
- +
118
- (
119
- importDict.empty()
120
- ? ""
121
- : "\n" + importDict.toScript(outDir) + "\n"
122
- )
123
- + content;
124
- }
125
-
126
- content = "/**\n"
127
- + " * @packageDocumentation\n"
128
- + ` * @module ${directory.module}\n`
129
- + " */\n"
130
- + "//================================================================\n"
131
- + content;
132
- await fs.promises.writeFile(`${outDir}/index.ts`, content, "utf8");
133
- }
134
- }
135
-
136
- class Directory
137
- {
138
- public readonly module: string;
139
- public readonly directories: HashMap<string, Directory>;
140
- public readonly routes: IRoute[];
141
-
142
- public constructor(readonly parent: Directory | null, readonly name: string)
143
- {
144
- this.directories = new HashMap();
145
- this.routes = [];
146
- this.module = (this.parent !== null)
147
- ? `${this.parent.module}.${name}`
148
- : `api.${name}`;
149
- }
150
- }
@@ -1,201 +0,0 @@
1
- import * as tsc from "typescript";
2
- import { Pair } from "tstl/utility/Pair";
3
- import { Vector } from "tstl/container/Vector";
4
-
5
- import { IRoute } from "../structures/IRoute";
6
-
7
- export namespace FunctionGenerator
8
- {
9
- export function generate(assert: boolean, route: IRoute): string
10
- {
11
- const query: IRoute.IParameter | undefined = route.parameters.find(param => param.category === "query");
12
- const input: IRoute.IParameter | undefined = route.parameters.find(param => param.category === "body");
13
-
14
- return [head, body, tail]
15
- .map(closure => closure(route, query, input, assert))
16
- .filter(str => !!str)
17
- .join("\n");
18
- }
19
-
20
- /* ---------------------------------------------------------
21
- BODY
22
- --------------------------------------------------------- */
23
- function body
24
- (
25
- route: IRoute,
26
- query: IRoute.IParameter | undefined,
27
- input: IRoute.IParameter | undefined,
28
- assert: boolean
29
- ): string
30
- {
31
- // FETCH ARGUMENTS WITH REQUST BODY
32
- const parameters = filter_parameters(route, query);
33
- const fetchArguments: string[] =
34
- [
35
- "connection",
36
- `${route.name}.ENCRYPTED`,
37
- `${route.name}.METHOD`,
38
- `${route.name}.path(${parameters.map(p => p.name).join(", ")})`
39
- ];
40
- if (input !== undefined)
41
- fetchArguments.push(input.name);
42
-
43
- const assertions: string = assert === true && route.parameters.length !== 0
44
- ? route.parameters
45
- .map(param => ` assertType<typeof ${param.name}>(${param.name});`)
46
- .join("\n") + "\n\n"
47
- : "";
48
-
49
- // RETURNS WITH FINALIZATION
50
- return "{\n"
51
- + assertions
52
- + " return Fetcher.fetch\n"
53
- + " (\n"
54
- + fetchArguments.map(param => ` ${param}`).join(",\n") + "\n"
55
- + " );\n"
56
- + "}";
57
- }
58
-
59
- function filter_parameters(route: IRoute, query: IRoute.IParameter | undefined): IRoute.IParameter[]
60
- {
61
- const parameters = route.parameters.filter(param => param.category === "param");
62
- if (query)
63
- parameters.push(query);
64
- return parameters;
65
- }
66
-
67
- /* ---------------------------------------------------------
68
- HEAD & TAIL
69
- --------------------------------------------------------- */
70
- function head
71
- (
72
- route: IRoute,
73
- query: IRoute.IParameter | undefined,
74
- input: IRoute.IParameter | undefined
75
- ): string
76
- {
77
- //----
78
- // CONSTRUCT COMMENT
79
- //----
80
- // MAIN DESCRIPTION
81
- let comment: string = route.comments.map(comment => `${comment.kind === "linkText" ? " " : ""}${comment.text}`).join("");
82
- if (comment !== "")
83
- comment += "\n\n";
84
-
85
- // FILTER TAGS (VULNERABLE PARAMETERS WOULD BE REMOVED)
86
- const tagList: tsc.JSDocTagInfo[] = route.tags.filter(tag => tag.text !== undefined);
87
- if (tagList.length !== 0)
88
- {
89
- const index: number = tagList.findIndex(t => t.name === "param");
90
- if (index !== -1)
91
- {
92
- const capsule: Vector<tsc.JSDocTagInfo> = Vector.wrap(tagList);
93
- capsule.insert(capsule.nth(index), {
94
- name: "param",
95
- text: [
96
- {
97
- kind: "parameterName",
98
- text: "connection"
99
- },
100
- {
101
- kind: "space",
102
- text: " "
103
- },
104
- {
105
- kind: "text",
106
- text: "connection Information of the remote HTTP(s) server with headers (+encryption password)"
107
- }
108
- ]
109
- });
110
- }
111
- comment += tagList
112
- .map(tag => `@${tag.name} ${tag.text!.map(elem => elem.text).join("")}`)
113
- .join("\n") + "\n\n";
114
- }
115
-
116
- // COMPLETE THE COMMENT
117
- comment += `@nestia Generated by Nestia - https://github.com/samchon/nestia\n`;
118
- comment += `@controller ${route.symbol}\n`;
119
- comment += `@path ${route.method} ${route.path}`;
120
-
121
- //----
122
- // FINALIZATION
123
- //----
124
- // REFORM PARAMETERS TEXT
125
- const parameters: string[] =
126
- [
127
- "connection: IConnection",
128
- ...route.parameters.map(param =>
129
- {
130
- const type: string = (param === query || param === input)
131
- ? `Primitive<${route.name}.${param === query ? "Query" : "Input"}>`
132
- : param.type
133
- return `${param.name}: ${type}`;
134
- })
135
- ];
136
-
137
- // OUTPUT TYPE
138
- const output: string = route.output === "void"
139
- ? "void"
140
- : `${route.name}.Output`;
141
-
142
- // RETURNS WITH CONSTRUCTION
143
- return ""
144
- + "/**\n"
145
- + comment.split("\r\n").join("\n").split("\n").map(str => ` * ${str}`).join("\n") + "\n"
146
- + " */\n"
147
- + `export function ${route.name}\n`
148
- + ` (\n`
149
- + `${parameters.map(str => ` ${str}`).join(",\n")}\n`
150
- + ` ): Promise<${output}>`;
151
- }
152
-
153
- function tail
154
- (
155
- route: IRoute,
156
- query: IRoute.IParameter | undefined,
157
- input: IRoute.IParameter | undefined
158
- ): string | null
159
- {
160
- // LIST UP TYPES
161
- const types: Pair<string, string>[] = [];
162
- if (query !== undefined)
163
- types.push(new Pair("Query", query.type));
164
- if (input !== undefined)
165
- types.push(new Pair("Input", input.type));
166
- if (route.output !== "void")
167
- types.push(new Pair("Output", route.output));
168
-
169
- // PATH WITH PARAMETERS
170
- const parameters = filter_parameters(route, query);
171
- let path: string = route.path;
172
- for (const param of parameters)
173
- if (param.category === "param")
174
- path = path.replace(`:${param.field}`, `\${${param.name}}`);
175
- path = (query !== undefined)
176
- ? `\`${path}?\${new URLSearchParams(${query.name} as any).toString()}\``
177
- : `\`${path}\``;
178
-
179
- return `export namespace ${route.name}\n`
180
- + "{\n"
181
- +
182
- (
183
- types.length !== 0
184
- ? types.map(tuple => ` export type ${tuple.first} = Primitive<${tuple.second}>;`).join("\n") + "\n"
185
- : ""
186
- )
187
- + "\n"
188
- + ` export const METHOD = "${route.method}" as const;\n`
189
- + ` export const PATH: string = "${route.path}";\n`
190
- + ` export const ENCRYPTED: Fetcher.IEncrypted = {\n`
191
- + ` request: ${input !== undefined && input.encrypted},\n`
192
- + ` response: ${route.encrypted},\n`
193
- + ` };\n`
194
- + "\n"
195
- + ` export function path(${parameters.map(param => `${param.name}: ${param.type}`).join(", ")}): string\n`
196
- + ` {\n`
197
- + ` return ${path};\n`
198
- + ` }\n`
199
- + "}";
200
- }
201
- }
@@ -1,39 +0,0 @@
1
- import * as fs from "fs";
2
- import { DirectoryUtil } from "../utils/DirectoryUtil";
3
-
4
- import { IRoute } from "../structures/IRoute";
5
- import { FileGenerator } from "./FileGenerator";
6
- import { IConfiguration } from "../IConfiguration";
7
-
8
- export namespace SdkGenerator
9
- {
10
- export async function generate
11
- (
12
- config: IConfiguration,
13
- routeList: IRoute[],
14
- ): Promise<void>
15
- {
16
- // PREPARE NEW DIRECTORIES
17
- try { await fs.promises.mkdir(config.output); } catch {}
18
-
19
- // BUNDLING
20
- const bundle: string[] = await fs.promises.readdir(BUNDLE);
21
- for (const file of bundle)
22
- {
23
- const current: string = `${BUNDLE}/${file}`;
24
- const stats: fs.Stats = await fs.promises.stat(current);
25
-
26
- if (stats.isFile() === true)
27
- {
28
- const content: string = await fs.promises.readFile(current, "utf8");
29
- await fs.promises.writeFile(`${config.output}/${file}`, content, "utf8");
30
- }
31
- }
32
- await DirectoryUtil.copy(BUNDLE + "/__internal", config.output + "/__internal");
33
-
34
- // FUNCTIONAL
35
- await FileGenerator.generate(config, routeList);
36
- }
37
- }
38
-
39
- const BUNDLE = __dirname + "/../bundle";
@@ -1,36 +0,0 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import { InvalidArgument } from "tstl/exception/InvalidArgument";
4
- import { Primitive } from "nestia-fetcher";
5
- import { Singleton } from "tstl/thread/Singleton";
6
- import { assertType, is } from "typescript-is";
7
-
8
- import { IConfiguration } from "../IConfiguration";
9
-
10
- export namespace NestiaConfig
11
- {
12
- export function get(): Promise<IConfiguration | null>
13
- {
14
- return singleton.get();
15
- }
16
-
17
- function assert(config: IConfiguration): IConfiguration
18
- {
19
- assertType<Omit<typeof config, "input"|"compilerOptions">>(config);
20
- if (is<string>(config.input) === false
21
- && is<string[]>(config.input) === false
22
- && is<IConfiguration.IInput>(config.input) === false)
23
- throw new InvalidArgument("Error on NestiaConfig.get(): invalid input type.");
24
-
25
- return config;
26
- }
27
-
28
- const singleton = new Singleton(async () =>
29
- {
30
- if (fs.existsSync("nestia.config.ts") === false)
31
- return null;
32
-
33
- const config: IConfiguration = await import(path.resolve("nestia.config.ts"));
34
- return assert(Primitive.clone(config));
35
- });
36
- }