@vida-global/core 1.3.0 → 1.3.1
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.
|
@@ -59,7 +59,7 @@ function resolveAutoIncrementColumns(details) {
|
|
|
59
59
|
if (!details.defaultValue) return;
|
|
60
60
|
|
|
61
61
|
const regExp = /^nextval\(\w+_seq::regclass\)$/;
|
|
62
|
-
if (details.defaultValue
|
|
62
|
+
if (regExp.test(details.defaultValue)) {
|
|
63
63
|
delete details.defaultValue;
|
|
64
64
|
delete details.allowNull;
|
|
65
65
|
details.autoIncrement = true;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const { ControllerImporter } = require('./controllerImporter');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ApiDocsGenerator {
|
|
5
|
+
#controllerDirectories
|
|
6
|
+
#controllers;
|
|
7
|
+
#docs = {};
|
|
8
|
+
|
|
9
|
+
constructor(server) {
|
|
10
|
+
this.#controllerDirectories = server.controllerDirectories;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
generateDocs() {
|
|
15
|
+
console.log("\n\n");
|
|
16
|
+
this.controllers.forEach(controller => {
|
|
17
|
+
controller.actions.forEach(action => {
|
|
18
|
+
this.generateDocsForAction(action);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
console.log("\n\n");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
generateDocsForAction(action) {
|
|
26
|
+
const endpoint = this.formatEndpoint(action);
|
|
27
|
+
this.#docs[endpoint] = this.#docs[endpoint] || {};
|
|
28
|
+
const actionDocs = this.#docs[endpoint][action.method.toLowerCase()] = {foo: 1};
|
|
29
|
+
console.log(actionDocs);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
get controllers() {
|
|
34
|
+
if (!this.#controllers) {
|
|
35
|
+
const controllerImporter = new ControllerImporter(this.#controllerDirectories);
|
|
36
|
+
this.#controllers = controllerImporter.controllers;
|
|
37
|
+
}
|
|
38
|
+
return this.#controllers;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/***********************************************************************************************
|
|
43
|
+
* OPENAPI COMPONENTS
|
|
44
|
+
***********************************************************************************************/
|
|
45
|
+
formatEndpoint(action) {
|
|
46
|
+
const endpoint = action.path.replace(/:([^/]+)/g, '{$1}');
|
|
47
|
+
return endpoint;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
module.exports = {
|
|
54
|
+
ApiDocsGenerator
|
|
55
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const { VidaServerController } = require('./serverController');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ControllerImporter {
|
|
6
|
+
#controllerDirectories;
|
|
7
|
+
#controllers;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
constructor(controllerDirectories) {
|
|
11
|
+
if (!Array.isArray(controllerDirectories)) {
|
|
12
|
+
controllerDirectories = [controllerDirectories];
|
|
13
|
+
}
|
|
14
|
+
this.#controllerDirectories = controllerDirectories;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
get controllers() {
|
|
19
|
+
if (!this.#controllers) {
|
|
20
|
+
this.#importControllers();
|
|
21
|
+
}
|
|
22
|
+
return this.#controllers;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
#importControllers() {
|
|
27
|
+
this.#controllers = [];
|
|
28
|
+
this.#controllerDirectories.forEach(dir => {
|
|
29
|
+
this.#importDirectory(dir, dir);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
#importDirectory(dir, topLevelDirectory) {
|
|
35
|
+
fs.readdirSync(dir).forEach((f => {
|
|
36
|
+
const filePath = `${dir}/${f}`;
|
|
37
|
+
if (fs.lstatSync(filePath).isDirectory()) {
|
|
38
|
+
this.#importDirectory(filePath, topLevelDirectory);
|
|
39
|
+
} else if (f.endsWith('.js')) {
|
|
40
|
+
this.#importFromFile(filePath, dir, topLevelDirectory);
|
|
41
|
+
}
|
|
42
|
+
}).bind(this));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
#importFromFile(filePath, dir, topLevelDirectory) {
|
|
47
|
+
const exports = Object.values(require(filePath));
|
|
48
|
+
exports.forEach(_export => {
|
|
49
|
+
if (_export.prototype instanceof VidaServerController) {
|
|
50
|
+
const directoryPrefix = dir.replace(topLevelDirectory, '');
|
|
51
|
+
_export.directoryPrefix = directoryPrefix;
|
|
52
|
+
this.#controllers.push(_export);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
module.exports = {
|
|
61
|
+
ControllerImporter
|
|
62
|
+
}
|