nestia 3.0.15 → 3.0.16-dev.20220930
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.
- package/lib/IConfiguration.d.ts +110 -110
- package/lib/IConfiguration.js +2 -2
- package/lib/NestiaApplication.d.ts +11 -11
- package/lib/NestiaApplication.js +155 -155
- package/lib/analyses/ControllerAnalyzer.d.ts +6 -6
- package/lib/analyses/ControllerAnalyzer.js +105 -105
- package/lib/analyses/GenericAnalyzer.d.ts +5 -5
- package/lib/analyses/GenericAnalyzer.js +40 -40
- package/lib/analyses/ImportAnalyzer.d.ts +13 -13
- package/lib/analyses/ImportAnalyzer.js +83 -83
- package/lib/analyses/PathAnalyzer.d.ts +5 -5
- package/lib/analyses/PathAnalyzer.js +50 -50
- package/lib/analyses/ReflectAnalyzer.d.ts +4 -4
- package/lib/analyses/ReflectAnalyzer.js +229 -229
- package/lib/analyses/SourceFinder.d.ts +4 -4
- package/lib/analyses/SourceFinder.js +69 -69
- package/lib/executable/internal/CompilerOptions.d.ts +11 -11
- package/lib/executable/internal/CompilerOptions.js +17 -17
- package/lib/executable/internal/NestiaCommand.d.ts +4 -4
- package/lib/executable/internal/NestiaCommand.js +127 -127
- package/lib/executable/internal/NestiaConfig.d.ts +4 -4
- package/lib/executable/internal/NestiaConfig.js +521 -521
- package/lib/executable/internal/nestia.config.getter.d.ts +1 -1
- package/lib/executable/internal/nestia.config.getter.js +23 -23
- package/lib/executable/nestia.d.ts +2 -2
- package/lib/executable/nestia.js +54 -54
- package/lib/generates/FileGenerator.d.ts +5 -5
- package/lib/generates/FileGenerator.js +136 -136
- package/lib/generates/FunctionGenerator.d.ts +5 -5
- package/lib/generates/FunctionGenerator.js +203 -203
- package/lib/generates/SdkGenerator.d.ts +7 -7
- package/lib/generates/SdkGenerator.js +46 -46
- package/lib/generates/SwaggerGenerator.d.ts +6 -6
- package/lib/generates/SwaggerGenerator.js +235 -235
- package/lib/index.d.ts +2 -2
- package/lib/index.js +27 -27
- package/lib/module.d.ts +2 -2
- package/lib/module.js +18 -18
- package/lib/structures/IController.d.ts +23 -23
- package/lib/structures/IController.js +2 -2
- package/lib/structures/IRoute.d.ts +24 -24
- package/lib/structures/IRoute.js +2 -2
- package/lib/structures/ISwagger.d.ts +48 -48
- package/lib/structures/ISwagger.js +2 -2
- package/lib/structures/ITypeTuple.d.ts +5 -5
- package/lib/structures/ITypeTuple.js +2 -2
- package/lib/structures/MethodType.d.ts +4 -4
- package/lib/structures/MethodType.js +13 -13
- package/lib/structures/ParamCategory.d.ts +1 -1
- package/lib/structures/ParamCategory.js +2 -2
- package/lib/structures/TypeEntry.d.ts +9 -9
- package/lib/structures/TypeEntry.js +20 -20
- package/lib/utils/ArrayUtil.d.ts +5 -5
- package/lib/utils/ArrayUtil.js +38 -38
- package/lib/utils/DirectoryUtil.d.ts +5 -5
- package/lib/utils/DirectoryUtil.js +61 -61
- package/lib/utils/ImportDictionary.d.ts +6 -6
- package/lib/utils/ImportDictionary.js +49 -49
- package/lib/utils/MapUtil.d.ts +3 -3
- package/lib/utils/MapUtil.js +15 -15
- package/lib/utils/StripEnums.d.ts +3 -3
- package/lib/utils/StripEnums.js +2 -2
- package/package.json +1 -1
- package/preliminaries/nestia.config.ts +70 -70
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const WorkerServer_1 = require("tgrid/protocols/workers/WorkerServer");
|
|
13
|
-
const NestiaConfig_1 = require("./NestiaConfig");
|
|
14
|
-
function main() {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const worker = new WorkerServer_1.WorkerServer();
|
|
17
|
-
yield worker.open(NestiaConfig_1.NestiaConfig);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
main().catch((exp) => {
|
|
21
|
-
console.log(exp);
|
|
22
|
-
process.exit(-1);
|
|
23
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const WorkerServer_1 = require("tgrid/protocols/workers/WorkerServer");
|
|
13
|
+
const NestiaConfig_1 = require("./NestiaConfig");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = new WorkerServer_1.WorkerServer();
|
|
17
|
+
yield worker.open(NestiaConfig_1.NestiaConfig);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
main().catch((exp) => {
|
|
21
|
+
console.log(exp);
|
|
22
|
+
process.exit(-1);
|
|
23
|
+
});
|
|
24
24
|
//# sourceMappingURL=nestia.config.getter.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
export {};
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export {};
|
package/lib/executable/nestia.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const child_process_1 = __importDefault(require("child_process"));
|
|
17
|
-
const fs_1 = __importDefault(require("fs"));
|
|
18
|
-
const process_1 = __importDefault(require("process"));
|
|
19
|
-
const NestiaCommand_1 = require("./internal/NestiaCommand");
|
|
20
|
-
function dependencies() {
|
|
21
|
-
// INSTALL DEPENDENCIES
|
|
22
|
-
for (const lib of ["nestia-fetcher", "typescript-json"]) {
|
|
23
|
-
const command = `npm install ${lib}`;
|
|
24
|
-
child_process_1.default.execSync(command, { stdio: "inherit" });
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function initialize() {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
if (fs_1.default.existsSync("nestia.config.ts") === true)
|
|
30
|
-
throw new Error(`Error on nestia.initialize(): "nestia.config.ts" file already has been configured.`);
|
|
31
|
-
const content = yield fs_1.default.promises.readFile(`${__dirname}/../../preliminaries/nestia.config.ts`, "utf8");
|
|
32
|
-
yield fs_1.default.promises.writeFile("nestia.config.ts", content, "utf8");
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function main() {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const type = process_1.default.argv[2];
|
|
38
|
-
const argv = process_1.default.argv.slice(3);
|
|
39
|
-
if (type === "install")
|
|
40
|
-
dependencies();
|
|
41
|
-
else if (type === "init")
|
|
42
|
-
yield initialize();
|
|
43
|
-
else if (type === "sdk")
|
|
44
|
-
yield NestiaCommand_1.NestiaCommand.sdk(argv);
|
|
45
|
-
else if (type === "swagger")
|
|
46
|
-
yield NestiaCommand_1.NestiaCommand.swagger(argv);
|
|
47
|
-
else
|
|
48
|
-
throw new Error(`nestia supports only three commands; (install, sdk, swagger), however you've typed the "${process_1.default.argv[2]}"`);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
main().catch((exp) => {
|
|
52
|
-
console.log(exp.message);
|
|
53
|
-
process_1.default.exit(-1);
|
|
54
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const child_process_1 = __importDefault(require("child_process"));
|
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
|
18
|
+
const process_1 = __importDefault(require("process"));
|
|
19
|
+
const NestiaCommand_1 = require("./internal/NestiaCommand");
|
|
20
|
+
function dependencies() {
|
|
21
|
+
// INSTALL DEPENDENCIES
|
|
22
|
+
for (const lib of ["nestia-fetcher", "typescript-json"]) {
|
|
23
|
+
const command = `npm install ${lib}`;
|
|
24
|
+
child_process_1.default.execSync(command, { stdio: "inherit" });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function initialize() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
if (fs_1.default.existsSync("nestia.config.ts") === true)
|
|
30
|
+
throw new Error(`Error on nestia.initialize(): "nestia.config.ts" file already has been configured.`);
|
|
31
|
+
const content = yield fs_1.default.promises.readFile(`${__dirname}/../../preliminaries/nestia.config.ts`, "utf8");
|
|
32
|
+
yield fs_1.default.promises.writeFile("nestia.config.ts", content, "utf8");
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function main() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const type = process_1.default.argv[2];
|
|
38
|
+
const argv = process_1.default.argv.slice(3);
|
|
39
|
+
if (type === "install")
|
|
40
|
+
dependencies();
|
|
41
|
+
else if (type === "init")
|
|
42
|
+
yield initialize();
|
|
43
|
+
else if (type === "sdk")
|
|
44
|
+
yield NestiaCommand_1.NestiaCommand.sdk(argv);
|
|
45
|
+
else if (type === "swagger")
|
|
46
|
+
yield NestiaCommand_1.NestiaCommand.swagger(argv);
|
|
47
|
+
else
|
|
48
|
+
throw new Error(`nestia supports only three commands; (install, sdk, swagger), however you've typed the "${process_1.default.argv[2]}"`);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
main().catch((exp) => {
|
|
52
|
+
console.log(exp.message);
|
|
53
|
+
process_1.default.exit(-1);
|
|
54
|
+
});
|
|
55
55
|
//# sourceMappingURL=nestia.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IConfiguration } from "../IConfiguration";
|
|
2
|
-
import { IRoute } from "../structures/IRoute";
|
|
3
|
-
export declare namespace FileGenerator {
|
|
4
|
-
function generate(config: IConfiguration, routeList: IRoute[]): Promise<void>;
|
|
5
|
-
}
|
|
1
|
+
import { IConfiguration } from "../IConfiguration";
|
|
2
|
+
import { IRoute } from "../structures/IRoute";
|
|
3
|
+
export declare namespace FileGenerator {
|
|
4
|
+
function generate(config: IConfiguration, routeList: IRoute[]): Promise<void>;
|
|
5
|
+
}
|
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.FileGenerator = void 0;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const HashMap_1 = require("tstl/container/HashMap");
|
|
18
|
-
const ImportDictionary_1 = require("../utils/ImportDictionary");
|
|
19
|
-
const FunctionGenerator_1 = require("./FunctionGenerator");
|
|
20
|
-
var FileGenerator;
|
|
21
|
-
(function (FileGenerator) {
|
|
22
|
-
/* ---------------------------------------------------------
|
|
23
|
-
CONSTRUCTOR
|
|
24
|
-
--------------------------------------------------------- */
|
|
25
|
-
function generate(config, routeList) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
// CONSTRUCT FOLDER TREE
|
|
28
|
-
const root = new Directory(null, "functional");
|
|
29
|
-
for (const route of routeList)
|
|
30
|
-
emplace(root, route);
|
|
31
|
-
// RELOCATE FOR ONLY ONE CONTROLLER METHOD IN AN URL CASE
|
|
32
|
-
relocate(root);
|
|
33
|
-
// ITERATE FILES
|
|
34
|
-
yield iterate(config, config.output + "/functional", root);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
FileGenerator.generate = generate;
|
|
38
|
-
function emplace(directory, route) {
|
|
39
|
-
// SEPARATE IDENTIFIERS
|
|
40
|
-
const identifiers = route.path
|
|
41
|
-
.split("/")
|
|
42
|
-
.filter((str) => str[0] !== ":" && str.length !== 0)
|
|
43
|
-
.map((str) => str.split("-").join("_").split(".").join("_"));
|
|
44
|
-
// OPEN DIRECTORIES
|
|
45
|
-
for (const key of identifiers)
|
|
46
|
-
directory = directory.directories.take(key, () => new Directory(directory, key));
|
|
47
|
-
// ADD ROUTE
|
|
48
|
-
directory.routes.push(route);
|
|
49
|
-
}
|
|
50
|
-
function relocate(directory) {
|
|
51
|
-
if (directory.parent !== null &&
|
|
52
|
-
directory.directories.empty() &&
|
|
53
|
-
directory.routes.length === 1 &&
|
|
54
|
-
directory.name === directory.routes[0].name) {
|
|
55
|
-
directory.parent.routes.push(directory.routes[0]);
|
|
56
|
-
directory.parent.directories.erase(directory.name);
|
|
57
|
-
}
|
|
58
|
-
else if (directory.directories.empty() === false)
|
|
59
|
-
for (const it of directory.directories)
|
|
60
|
-
relocate(it.second);
|
|
61
|
-
}
|
|
62
|
-
/* ---------------------------------------------------------
|
|
63
|
-
FILE ITERATOR
|
|
64
|
-
--------------------------------------------------------- */
|
|
65
|
-
function iterate(config, outDir, directory) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
// CREATE A NEW DIRECTORY
|
|
68
|
-
try {
|
|
69
|
-
yield fs_1.default.promises.mkdir(outDir);
|
|
70
|
-
}
|
|
71
|
-
catch (_a) { }
|
|
72
|
-
// ITERATE CHILDREN
|
|
73
|
-
const content = [];
|
|
74
|
-
for (const it of directory.directories) {
|
|
75
|
-
yield iterate(config, `${outDir}/${it.first}`, it.second);
|
|
76
|
-
content.push(`export * as ${it.first} from "./${it.first}";`);
|
|
77
|
-
}
|
|
78
|
-
if (content.length && directory.routes.length)
|
|
79
|
-
content.push("");
|
|
80
|
-
// ITERATE ROUTES
|
|
81
|
-
const importDict = new ImportDictionary_1.ImportDictionary();
|
|
82
|
-
directory.routes.forEach((route, i) => {
|
|
83
|
-
for (const tuple of route.imports)
|
|
84
|
-
for (const instance of tuple[1])
|
|
85
|
-
importDict.emplace(tuple[0], false, instance);
|
|
86
|
-
content.push(FunctionGenerator_1.FunctionGenerator.generate(config, route));
|
|
87
|
-
if (i !== directory.routes.length - 1)
|
|
88
|
-
content.push("");
|
|
89
|
-
});
|
|
90
|
-
// FINALIZE THE CONTENT
|
|
91
|
-
if (directory.routes.length !== 0) {
|
|
92
|
-
const primitived = config.primitive !== false &&
|
|
93
|
-
directory.routes.some((route) => route.output.name !== "void" ||
|
|
94
|
-
route.parameters.some((param) => param.category !== "param"));
|
|
95
|
-
const asserted = config.assert === true &&
|
|
96
|
-
directory.routes.some((route) => route.parameters.length !== 0);
|
|
97
|
-
const json = config.json === true &&
|
|
98
|
-
directory.routes.some((route) => route.method === "POST" ||
|
|
99
|
-
route.method === "PUT" ||
|
|
100
|
-
route.method === "PATCH");
|
|
101
|
-
const fetcher = ["Fetcher"];
|
|
102
|
-
if (primitived)
|
|
103
|
-
fetcher.push("Primitive");
|
|
104
|
-
const head = [
|
|
105
|
-
`import { ${fetcher.join(", ")} } from "nestia-fetcher";`,
|
|
106
|
-
`import type { IConnection } from "nestia-fetcher";`,
|
|
107
|
-
];
|
|
108
|
-
if (asserted || json)
|
|
109
|
-
head.push(`import TSON from "typescript-json";`);
|
|
110
|
-
if (!importDict.empty())
|
|
111
|
-
head.push("", importDict.toScript(outDir));
|
|
112
|
-
content.push(...head, "", ...content.splice(0, content.length));
|
|
113
|
-
}
|
|
114
|
-
const script = "/**\n" +
|
|
115
|
-
" * @packageDocumentation\n" +
|
|
116
|
-
` * @module ${directory.module}\n` +
|
|
117
|
-
" * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
|
|
118
|
-
" */\n" +
|
|
119
|
-
"//================================================================\n" +
|
|
120
|
-
content.join("\n");
|
|
121
|
-
yield fs_1.default.promises.writeFile(`${outDir}/index.ts`, script, "utf8");
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
})(FileGenerator = exports.FileGenerator || (exports.FileGenerator = {}));
|
|
125
|
-
class Directory {
|
|
126
|
-
constructor(parent, name) {
|
|
127
|
-
this.parent = parent;
|
|
128
|
-
this.name = name;
|
|
129
|
-
this.directories = new HashMap_1.HashMap();
|
|
130
|
-
this.routes = [];
|
|
131
|
-
this.module =
|
|
132
|
-
this.parent !== null
|
|
133
|
-
? `${this.parent.module}.${name}`
|
|
134
|
-
: `api.${name}`;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.FileGenerator = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const HashMap_1 = require("tstl/container/HashMap");
|
|
18
|
+
const ImportDictionary_1 = require("../utils/ImportDictionary");
|
|
19
|
+
const FunctionGenerator_1 = require("./FunctionGenerator");
|
|
20
|
+
var FileGenerator;
|
|
21
|
+
(function (FileGenerator) {
|
|
22
|
+
/* ---------------------------------------------------------
|
|
23
|
+
CONSTRUCTOR
|
|
24
|
+
--------------------------------------------------------- */
|
|
25
|
+
function generate(config, routeList) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
// CONSTRUCT FOLDER TREE
|
|
28
|
+
const root = new Directory(null, "functional");
|
|
29
|
+
for (const route of routeList)
|
|
30
|
+
emplace(root, route);
|
|
31
|
+
// RELOCATE FOR ONLY ONE CONTROLLER METHOD IN AN URL CASE
|
|
32
|
+
relocate(root);
|
|
33
|
+
// ITERATE FILES
|
|
34
|
+
yield iterate(config, config.output + "/functional", root);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
FileGenerator.generate = generate;
|
|
38
|
+
function emplace(directory, route) {
|
|
39
|
+
// SEPARATE IDENTIFIERS
|
|
40
|
+
const identifiers = route.path
|
|
41
|
+
.split("/")
|
|
42
|
+
.filter((str) => str[0] !== ":" && str.length !== 0)
|
|
43
|
+
.map((str) => str.split("-").join("_").split(".").join("_"));
|
|
44
|
+
// OPEN DIRECTORIES
|
|
45
|
+
for (const key of identifiers)
|
|
46
|
+
directory = directory.directories.take(key, () => new Directory(directory, key));
|
|
47
|
+
// ADD ROUTE
|
|
48
|
+
directory.routes.push(route);
|
|
49
|
+
}
|
|
50
|
+
function relocate(directory) {
|
|
51
|
+
if (directory.parent !== null &&
|
|
52
|
+
directory.directories.empty() &&
|
|
53
|
+
directory.routes.length === 1 &&
|
|
54
|
+
directory.name === directory.routes[0].name) {
|
|
55
|
+
directory.parent.routes.push(directory.routes[0]);
|
|
56
|
+
directory.parent.directories.erase(directory.name);
|
|
57
|
+
}
|
|
58
|
+
else if (directory.directories.empty() === false)
|
|
59
|
+
for (const it of directory.directories)
|
|
60
|
+
relocate(it.second);
|
|
61
|
+
}
|
|
62
|
+
/* ---------------------------------------------------------
|
|
63
|
+
FILE ITERATOR
|
|
64
|
+
--------------------------------------------------------- */
|
|
65
|
+
function iterate(config, outDir, directory) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
// CREATE A NEW DIRECTORY
|
|
68
|
+
try {
|
|
69
|
+
yield fs_1.default.promises.mkdir(outDir);
|
|
70
|
+
}
|
|
71
|
+
catch (_a) { }
|
|
72
|
+
// ITERATE CHILDREN
|
|
73
|
+
const content = [];
|
|
74
|
+
for (const it of directory.directories) {
|
|
75
|
+
yield iterate(config, `${outDir}/${it.first}`, it.second);
|
|
76
|
+
content.push(`export * as ${it.first} from "./${it.first}";`);
|
|
77
|
+
}
|
|
78
|
+
if (content.length && directory.routes.length)
|
|
79
|
+
content.push("");
|
|
80
|
+
// ITERATE ROUTES
|
|
81
|
+
const importDict = new ImportDictionary_1.ImportDictionary();
|
|
82
|
+
directory.routes.forEach((route, i) => {
|
|
83
|
+
for (const tuple of route.imports)
|
|
84
|
+
for (const instance of tuple[1])
|
|
85
|
+
importDict.emplace(tuple[0], false, instance);
|
|
86
|
+
content.push(FunctionGenerator_1.FunctionGenerator.generate(config, route));
|
|
87
|
+
if (i !== directory.routes.length - 1)
|
|
88
|
+
content.push("");
|
|
89
|
+
});
|
|
90
|
+
// FINALIZE THE CONTENT
|
|
91
|
+
if (directory.routes.length !== 0) {
|
|
92
|
+
const primitived = config.primitive !== false &&
|
|
93
|
+
directory.routes.some((route) => route.output.name !== "void" ||
|
|
94
|
+
route.parameters.some((param) => param.category !== "param"));
|
|
95
|
+
const asserted = config.assert === true &&
|
|
96
|
+
directory.routes.some((route) => route.parameters.length !== 0);
|
|
97
|
+
const json = config.json === true &&
|
|
98
|
+
directory.routes.some((route) => route.method === "POST" ||
|
|
99
|
+
route.method === "PUT" ||
|
|
100
|
+
route.method === "PATCH");
|
|
101
|
+
const fetcher = ["Fetcher"];
|
|
102
|
+
if (primitived)
|
|
103
|
+
fetcher.push("Primitive");
|
|
104
|
+
const head = [
|
|
105
|
+
`import { ${fetcher.join(", ")} } from "nestia-fetcher";`,
|
|
106
|
+
`import type { IConnection } from "nestia-fetcher";`,
|
|
107
|
+
];
|
|
108
|
+
if (asserted || json)
|
|
109
|
+
head.push(`import TSON from "typescript-json";`);
|
|
110
|
+
if (!importDict.empty())
|
|
111
|
+
head.push("", importDict.toScript(outDir));
|
|
112
|
+
content.push(...head, "", ...content.splice(0, content.length));
|
|
113
|
+
}
|
|
114
|
+
const script = "/**\n" +
|
|
115
|
+
" * @packageDocumentation\n" +
|
|
116
|
+
` * @module ${directory.module}\n` +
|
|
117
|
+
" * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
|
|
118
|
+
" */\n" +
|
|
119
|
+
"//================================================================\n" +
|
|
120
|
+
content.join("\n");
|
|
121
|
+
yield fs_1.default.promises.writeFile(`${outDir}/index.ts`, script, "utf8");
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
})(FileGenerator = exports.FileGenerator || (exports.FileGenerator = {}));
|
|
125
|
+
class Directory {
|
|
126
|
+
constructor(parent, name) {
|
|
127
|
+
this.parent = parent;
|
|
128
|
+
this.name = name;
|
|
129
|
+
this.directories = new HashMap_1.HashMap();
|
|
130
|
+
this.routes = [];
|
|
131
|
+
this.module =
|
|
132
|
+
this.parent !== null
|
|
133
|
+
? `${this.parent.module}.${name}`
|
|
134
|
+
: `api.${name}`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
137
|
//# sourceMappingURL=FileGenerator.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IConfiguration } from "../IConfiguration";
|
|
2
|
-
import { IRoute } from "../structures/IRoute";
|
|
3
|
-
export declare namespace FunctionGenerator {
|
|
4
|
-
function generate(config: IConfiguration, route: IRoute): string;
|
|
5
|
-
}
|
|
1
|
+
import { IConfiguration } from "../IConfiguration";
|
|
2
|
+
import { IRoute } from "../structures/IRoute";
|
|
3
|
+
export declare namespace FunctionGenerator {
|
|
4
|
+
function generate(config: IConfiguration, route: IRoute): string;
|
|
5
|
+
}
|