axe-api 0.21.0 → 0.30.0-rc1
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/build/dev-kit/app/Config/Application.d.ts +3 -0
- package/build/dev-kit/app/Config/Application.js +14 -0
- package/build/dev-kit/app/Config/Database.d.ts +3 -0
- package/build/dev-kit/app/Config/Database.js +24 -0
- package/build/dev-kit/app/Events/UserEvent.d.ts +3 -0
- package/build/dev-kit/app/Events/UserEvent.js +16 -0
- package/build/dev-kit/app/Hooks/CustomerHook.d.ts +3 -0
- package/build/dev-kit/app/Hooks/CustomerHook.js +16 -0
- package/build/dev-kit/app/Hooks/EmployeeHook.d.ts +2 -0
- package/build/dev-kit/app/Hooks/EmployeeHook.js +16 -0
- package/build/dev-kit/app/Hooks/UserHook.d.ts +3 -0
- package/build/dev-kit/app/Hooks/UserHook.js +17 -0
- package/build/dev-kit/app/Models/Customer.d.ts +7 -0
- package/build/dev-kit/app/Models/Customer.js +15 -0
- package/build/dev-kit/app/Models/Employee.d.ts +9 -0
- package/build/dev-kit/app/Models/Employee.js +21 -0
- package/build/dev-kit/app/Models/EmployeeAddress.d.ts +8 -0
- package/build/dev-kit/app/Models/EmployeeAddress.js +18 -0
- package/build/dev-kit/app/Models/Post.d.ts +6 -0
- package/build/dev-kit/app/Models/Post.js +14 -0
- package/build/dev-kit/app/Models/User.d.ts +7 -0
- package/build/dev-kit/app/Models/User.js +23 -0
- package/build/dev-kit/app/Serialization/UserSerialization.d.ts +3 -0
- package/build/dev-kit/app/Serialization/UserSerialization.js +6 -0
- package/build/dev-kit/app/config.d.ts +3 -0
- package/build/dev-kit/app/config.js +31 -0
- package/build/dev-kit/app/init.d.ts +4 -0
- package/build/dev-kit/app/init.js +16 -0
- package/build/dev-kit/app/v1/Events/UserEvent.d.ts +3 -0
- package/build/dev-kit/app/v1/Events/UserEvent.js +16 -0
- package/build/dev-kit/app/v1/Hooks/CustomerHook.d.ts +3 -0
- package/build/dev-kit/app/v1/Hooks/CustomerHook.js +16 -0
- package/build/dev-kit/app/v1/Hooks/EmployeeHook.d.ts +2 -0
- package/build/dev-kit/app/v1/Hooks/EmployeeHook.js +16 -0
- package/build/dev-kit/app/v1/Hooks/UserHook.d.ts +3 -0
- package/build/dev-kit/app/v1/Hooks/UserHook.js +17 -0
- package/build/dev-kit/app/v1/Models/Customer.d.ts +7 -0
- package/build/dev-kit/app/v1/Models/Customer.js +15 -0
- package/build/dev-kit/app/v1/Models/Employee.d.ts +9 -0
- package/build/dev-kit/app/v1/Models/Employee.js +21 -0
- package/build/dev-kit/app/v1/Models/EmployeeAddress.d.ts +8 -0
- package/build/dev-kit/app/v1/Models/EmployeeAddress.js +18 -0
- package/build/dev-kit/app/v1/Models/Post.d.ts +6 -0
- package/build/dev-kit/app/v1/Models/Post.js +14 -0
- package/build/dev-kit/app/v1/Models/User.d.ts +7 -0
- package/build/dev-kit/app/v1/Models/User.js +23 -0
- package/build/dev-kit/app/v1/Serialization/PostSerialization.d.ts +3 -0
- package/build/dev-kit/app/v1/Serialization/PostSerialization.js +6 -0
- package/build/dev-kit/app/v1/Serialization/UserSerialization.d.ts +3 -0
- package/build/dev-kit/app/v1/Serialization/UserSerialization.js +5 -0
- package/build/dev-kit/app/v1/config.d.ts +3 -0
- package/build/dev-kit/app/v1/config.js +19 -0
- package/build/dev-kit/app/v1/init.d.ts +4 -0
- package/build/dev-kit/app/v1/init.js +16 -0
- package/build/dev-kit/app/v2/Events/UserEvent.d.ts +3 -0
- package/build/dev-kit/app/v2/Events/UserEvent.js +16 -0
- package/build/dev-kit/app/v2/Hooks/CustomerHook.d.ts +3 -0
- package/build/dev-kit/app/v2/Hooks/CustomerHook.js +16 -0
- package/build/dev-kit/app/v2/Hooks/EmployeeHook.d.ts +2 -0
- package/build/dev-kit/app/v2/Hooks/EmployeeHook.js +16 -0
- package/build/dev-kit/app/v2/Hooks/UserHook.d.ts +3 -0
- package/build/dev-kit/app/v2/Hooks/UserHook.js +17 -0
- package/build/dev-kit/app/v2/Models/Customer.d.ts +10 -0
- package/build/dev-kit/app/v2/Models/Customer.js +20 -0
- package/build/dev-kit/app/v2/Models/Employee.d.ts +9 -0
- package/build/dev-kit/app/v2/Models/Employee.js +21 -0
- package/build/dev-kit/app/v2/Models/EmployeeAddress.d.ts +8 -0
- package/build/dev-kit/app/v2/Models/EmployeeAddress.js +18 -0
- package/build/dev-kit/app/v2/Models/Post.d.ts +6 -0
- package/build/dev-kit/app/v2/Models/Post.js +14 -0
- package/build/dev-kit/app/v2/Models/User.d.ts +7 -0
- package/build/dev-kit/app/v2/Models/User.js +23 -0
- package/build/dev-kit/app/v2/Serialization/UserSerialization.d.ts +3 -0
- package/build/dev-kit/app/v2/Serialization/UserSerialization.js +5 -0
- package/build/dev-kit/app/v2/config.d.ts +3 -0
- package/build/dev-kit/app/v2/config.js +9 -0
- package/build/dev-kit/app/v2/init.d.ts +4 -0
- package/build/dev-kit/app/v2/init.js +16 -0
- package/build/dev-kit/app/v3/config.d.ts +3 -0
- package/build/dev-kit/app/v3/config.js +9 -0
- package/build/dev-kit/config.d.ts +3 -0
- package/build/dev-kit/config.js +31 -0
- package/build/dev-kit.d.ts +1 -0
- package/build/dev-kit.js +16 -0
- package/build/package.json +67 -0
- package/build/src/Builders/ModelTreeBuilder.d.ts +3 -0
- package/build/src/Builders/ModelTreeBuilder.js +21 -17
- package/build/src/Builders/RouterBuilder.d.ts +3 -0
- package/build/src/Builders/RouterBuilder.js +31 -26
- package/build/src/Enums.d.ts +13 -0
- package/build/src/Enums.js +15 -1
- package/build/src/Exceptions/AxeError.d.ts +8 -0
- package/build/src/Exceptions/AxeError.js +11 -0
- package/build/src/Handlers/AllHandler.js +6 -5
- package/build/src/Handlers/DestroyHandler.js +11 -1
- package/build/src/Handlers/DocsHandler.d.ts +3 -0
- package/build/src/Handlers/DocsHandler.js +22 -0
- package/build/src/Handlers/ForceDestroyHandler.d.ts +3 -0
- package/build/src/Handlers/ForceDestroyHandler.js +41 -0
- package/build/src/Handlers/HandlerFactory.d.ts +1 -1
- package/build/src/Handlers/HandlerFactory.js +4 -1
- package/build/src/Handlers/Helpers.d.ts +5 -3
- package/build/src/Handlers/Helpers.js +24 -14
- package/build/src/Handlers/PaginateHandler.js +6 -5
- package/build/src/Handlers/PatchHandler.js +4 -2
- package/build/src/Handlers/RoutesHandler.d.ts +3 -0
- package/build/src/Handlers/RoutesHandler.js +16 -0
- package/build/src/Handlers/ShowHandler.js +6 -5
- package/build/src/Handlers/StoreHandler.js +2 -2
- package/build/src/Handlers/UpdateHandler.js +4 -2
- package/build/src/Helpers.d.ts +4 -0
- package/build/src/Helpers.js +78 -0
- package/build/src/Interfaces.d.ts +36 -11
- package/build/src/Middlewares/acceptLanguageMiddleware.js +3 -5
- package/build/src/Model.d.ts +1 -1
- package/build/src/Model.js +3 -4
- package/build/src/Resolvers/FolderResolver.js +1 -0
- package/build/src/Resolvers/GeneralHookResolver.d.ts +4 -2
- package/build/src/Resolvers/GeneralHookResolver.js +5 -8
- package/build/src/Resolvers/ModelResolver.d.ts +4 -0
- package/build/src/Resolvers/ModelResolver.js +26 -8
- package/build/src/Resolvers/TransactionResolver.d.ts +4 -2
- package/build/src/Resolvers/TransactionResolver.js +5 -4
- package/build/src/Resolvers/VersionConfigResolver.d.ts +7 -0
- package/build/src/Resolvers/VersionConfigResolver.js +58 -0
- package/build/src/Resolvers/VersionResolver.d.ts +7 -0
- package/build/src/Resolvers/VersionResolver.js +65 -0
- package/build/src/Resolvers/index.d.ts +3 -2
- package/build/src/Resolvers/index.js +5 -3
- package/build/src/Server.d.ts +3 -2
- package/build/src/Server.js +73 -46
- package/build/src/Services/APIService.d.ts +16 -0
- package/build/src/Services/APIService.js +79 -0
- package/build/src/Services/DocumentationService.d.ts +3 -1
- package/build/src/Services/DocumentationService.js +6 -0
- package/build/src/Services/LogService.d.ts +4 -1
- package/build/src/Services/LogService.js +6 -0
- package/build/src/Services/ModelService.d.ts +3 -0
- package/build/src/Services/ModelService.js +4 -0
- package/build/src/Services/QueryService.js +3 -0
- package/build/src/Services/SchemaValidatorService.d.ts +3 -0
- package/build/src/Services/SchemaValidatorService.js +15 -8
- package/build/src/Services/index.d.ts +2 -1
- package/build/src/Services/index.js +3 -1
- package/build/src/Types.d.ts +2 -0
- package/build/src/Types.js +2 -0
- package/build/src/constants.d.ts +1 -0
- package/build/src/constants.js +2 -1
- package/package.json +2 -1
- package/readme.md +0 -24
- package/CHANGELOG.md +0 -202
|
@@ -3,18 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WithQueryResolver = exports.
|
|
6
|
+
exports.WithQueryResolver = exports.VersionResolver = exports.VersionConfigResolver = exports.TransactionResolver = exports.ModelResolver = exports.GeneralHookResolver = exports.FileResolver = exports.AcceptLanguageResolver = void 0;
|
|
7
7
|
const AcceptLanguageResolver_1 = __importDefault(require("./AcceptLanguageResolver"));
|
|
8
8
|
exports.AcceptLanguageResolver = AcceptLanguageResolver_1.default;
|
|
9
9
|
const FileResolver_1 = __importDefault(require("./FileResolver"));
|
|
10
10
|
exports.FileResolver = FileResolver_1.default;
|
|
11
|
-
const FolderResolver_1 = __importDefault(require("./FolderResolver"));
|
|
12
|
-
exports.FolderResolver = FolderResolver_1.default;
|
|
13
11
|
const GeneralHookResolver_1 = __importDefault(require("./GeneralHookResolver"));
|
|
14
12
|
exports.GeneralHookResolver = GeneralHookResolver_1.default;
|
|
15
13
|
const ModelResolver_1 = __importDefault(require("./ModelResolver"));
|
|
16
14
|
exports.ModelResolver = ModelResolver_1.default;
|
|
17
15
|
const TransactionResolver_1 = __importDefault(require("./TransactionResolver"));
|
|
18
16
|
exports.TransactionResolver = TransactionResolver_1.default;
|
|
17
|
+
const VersionConfigResolver_1 = __importDefault(require("./VersionConfigResolver"));
|
|
18
|
+
exports.VersionConfigResolver = VersionConfigResolver_1.default;
|
|
19
|
+
const VersionResolver_1 = __importDefault(require("./VersionResolver"));
|
|
20
|
+
exports.VersionResolver = VersionResolver_1.default;
|
|
19
21
|
const WithQueryResolver_1 = __importDefault(require("./WithQueryResolver"));
|
|
20
22
|
exports.WithQueryResolver = WithQueryResolver_1.default;
|
package/build/src/Server.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
declare class Server {
|
|
2
|
-
start(
|
|
2
|
+
start(rootFolder: string): Promise<void>;
|
|
3
3
|
private bindDependencies;
|
|
4
4
|
private loadExpress;
|
|
5
|
-
private
|
|
5
|
+
private analyzeVersions;
|
|
6
|
+
private loadGeneralConfiguration;
|
|
6
7
|
private listen;
|
|
7
8
|
}
|
|
8
9
|
export default Server;
|
package/build/src/Server.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -14,50 +37,51 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
38
|
const Resolvers_1 = require("./Resolvers");
|
|
16
39
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
17
41
|
const express_1 = __importDefault(require("express"));
|
|
18
42
|
const knex_1 = __importDefault(require("knex"));
|
|
19
43
|
const knex_schema_inspector_1 = __importDefault(require("knex-schema-inspector"));
|
|
20
44
|
const knex_paginate_1 = require("knex-paginate");
|
|
21
45
|
const Builders_1 = require("./Builders");
|
|
22
|
-
const HandlerFactory_1 = __importDefault(require("./Handlers/HandlerFactory"));
|
|
23
46
|
const Services_1 = require("./Services");
|
|
47
|
+
const DocsHandler_1 = __importDefault(require("./Handlers/DocsHandler"));
|
|
48
|
+
const RoutesHandler_1 = __importDefault(require("./Handlers/RoutesHandler"));
|
|
49
|
+
const Helpers_1 = require("./Helpers");
|
|
24
50
|
class Server {
|
|
25
|
-
start(
|
|
51
|
+
start(rootFolder) {
|
|
26
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
53
|
dotenv_1.default.config();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
54
|
+
try {
|
|
55
|
+
yield this.bindDependencies(rootFolder);
|
|
56
|
+
yield this.loadGeneralConfiguration();
|
|
57
|
+
yield this.loadExpress();
|
|
58
|
+
yield this.analyzeVersions();
|
|
59
|
+
yield this.listen();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (error.type === "AxeError") {
|
|
63
|
+
(0, Helpers_1.consoleAxeError)(error);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
36
69
|
});
|
|
37
70
|
}
|
|
38
|
-
bindDependencies(
|
|
71
|
+
bindDependencies(rootFolder) {
|
|
39
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
Services_1.
|
|
41
|
-
Services_1.
|
|
42
|
-
Services_1.IoCService.singleton("Models", () => models);
|
|
73
|
+
Services_1.APIService.setInsance(rootFolder);
|
|
74
|
+
const api = Services_1.APIService.getInstance();
|
|
43
75
|
Services_1.IoCService.singleton("SchemaInspector", () => knex_schema_inspector_1.default);
|
|
44
76
|
Services_1.IoCService.singleton("Database", () => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const
|
|
46
|
-
const database = (0, knex_1.default)(config.Database);
|
|
77
|
+
const database = (0, knex_1.default)(api.config.database);
|
|
47
78
|
(0, knex_paginate_1.attachPaginate)();
|
|
48
79
|
return database;
|
|
49
80
|
}));
|
|
50
81
|
Services_1.IoCService.singleton("App", () => __awaiter(this, void 0, void 0, function* () {
|
|
51
82
|
return (0, express_1.default)();
|
|
52
83
|
}));
|
|
53
|
-
Services_1.
|
|
54
|
-
return new HandlerFactory_1.default();
|
|
55
|
-
});
|
|
56
|
-
Services_1.IoCService.singleton("DocumentationService", () => __awaiter(this, void 0, void 0, function* () { return new Services_1.DocumentationService(); }));
|
|
57
|
-
Services_1.IoCService.singleton("LogService", () => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const config = yield Services_1.IoCService.use("Config");
|
|
59
|
-
return new Services_1.LogService(config.Application.logLevel);
|
|
60
|
-
}));
|
|
84
|
+
Services_1.LogService.setInstance(api.config.logLevel);
|
|
61
85
|
});
|
|
62
86
|
}
|
|
63
87
|
loadExpress() {
|
|
@@ -67,35 +91,38 @@ class Server {
|
|
|
67
91
|
app.use(express_1.default.json());
|
|
68
92
|
});
|
|
69
93
|
}
|
|
70
|
-
|
|
94
|
+
analyzeVersions() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const api = Services_1.APIService.getInstance();
|
|
97
|
+
yield new Resolvers_1.VersionResolver().resolve();
|
|
98
|
+
for (const version of api.versions) {
|
|
99
|
+
yield new Resolvers_1.VersionConfigResolver(version).resolve();
|
|
100
|
+
yield new Resolvers_1.ModelResolver(version).resolve();
|
|
101
|
+
yield new Services_1.SchemaValidatorService(version).validate();
|
|
102
|
+
yield new Builders_1.ModelTreeBuilder(version).build();
|
|
103
|
+
yield new Builders_1.RouterBuilder(version).build();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
loadGeneralConfiguration() {
|
|
71
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
yield
|
|
75
|
-
|
|
109
|
+
const api = Services_1.APIService.getInstance();
|
|
110
|
+
const generalConfigFile = path_1.default.join(api.appFolder, "config");
|
|
111
|
+
const { default: content } = yield Promise.resolve().then(() => __importStar(require(generalConfigFile)));
|
|
112
|
+
api.setConfig(content);
|
|
76
113
|
});
|
|
77
114
|
}
|
|
78
115
|
listen() {
|
|
79
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const config = yield Services_1.IoCService.use("Config");
|
|
81
117
|
const app = yield Services_1.IoCService.use("App");
|
|
82
|
-
const logger =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
res.json({
|
|
88
|
-
routes: docs.get(),
|
|
89
|
-
modelTree,
|
|
90
|
-
});
|
|
91
|
-
}));
|
|
92
|
-
app.get("/docs/routes", (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const docs = yield Services_1.IoCService.useByType("DocumentationService");
|
|
94
|
-
res.json(docs.get().map((route) => `${route.method} ${route.url}`));
|
|
95
|
-
}));
|
|
118
|
+
const logger = Services_1.LogService.getInstance();
|
|
119
|
+
const api = Services_1.APIService.getInstance();
|
|
120
|
+
if (api.config.env === "development") {
|
|
121
|
+
app.get("/docs", DocsHandler_1.default);
|
|
122
|
+
app.get("/routes", RoutesHandler_1.default);
|
|
96
123
|
}
|
|
97
|
-
app.listen(config.
|
|
98
|
-
logger.info(`API listens requests on http://localhost:${config.
|
|
124
|
+
app.listen(api.config.port, () => {
|
|
125
|
+
logger.info(`API listens requests on http://localhost:${api.config.port}`);
|
|
99
126
|
});
|
|
100
127
|
});
|
|
101
128
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IApplicationConfig, IVersion } from "../Interfaces";
|
|
2
|
+
declare class APIService {
|
|
3
|
+
private folders;
|
|
4
|
+
private static instance;
|
|
5
|
+
constructor(rootFolder: string);
|
|
6
|
+
static getInstance(): APIService;
|
|
7
|
+
static setInsance(rootFolder: string): void;
|
|
8
|
+
get rootFolder(): string;
|
|
9
|
+
get appFolder(): string;
|
|
10
|
+
get versions(): IVersion[];
|
|
11
|
+
get config(): IApplicationConfig;
|
|
12
|
+
setConfig(config: IApplicationConfig): void;
|
|
13
|
+
addVersion(name: string): void;
|
|
14
|
+
getVersion(name: string): IVersion;
|
|
15
|
+
}
|
|
16
|
+
export default APIService;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const Enums_1 = require("../Enums");
|
|
8
|
+
const ModelListService_1 = __importDefault(require("./ModelListService"));
|
|
9
|
+
class APIService {
|
|
10
|
+
constructor(rootFolder) {
|
|
11
|
+
this.folders = {
|
|
12
|
+
rootFolder: rootFolder,
|
|
13
|
+
appFolder: path_1.default.join(rootFolder, "app"),
|
|
14
|
+
versions: [],
|
|
15
|
+
config: {
|
|
16
|
+
env: "production",
|
|
17
|
+
port: 3000,
|
|
18
|
+
logLevel: Enums_1.LogLevels.INFO,
|
|
19
|
+
prefix: "/api",
|
|
20
|
+
database: {},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
static getInstance() {
|
|
25
|
+
return APIService.instance;
|
|
26
|
+
}
|
|
27
|
+
static setInsance(rootFolder) {
|
|
28
|
+
if (APIService.instance) {
|
|
29
|
+
throw new Error(`The instance already created: ${APIService.name}`);
|
|
30
|
+
}
|
|
31
|
+
APIService.instance = new APIService(rootFolder);
|
|
32
|
+
}
|
|
33
|
+
get rootFolder() {
|
|
34
|
+
return this.folders.rootFolder;
|
|
35
|
+
}
|
|
36
|
+
get appFolder() {
|
|
37
|
+
return this.folders.appFolder;
|
|
38
|
+
}
|
|
39
|
+
get versions() {
|
|
40
|
+
return this.folders.versions;
|
|
41
|
+
}
|
|
42
|
+
get config() {
|
|
43
|
+
return this.folders.config;
|
|
44
|
+
}
|
|
45
|
+
setConfig(config) {
|
|
46
|
+
this.folders.config = config;
|
|
47
|
+
}
|
|
48
|
+
addVersion(name) {
|
|
49
|
+
const root = path_1.default.join(this.folders.appFolder, name);
|
|
50
|
+
this.folders.versions.push({
|
|
51
|
+
name,
|
|
52
|
+
config: {
|
|
53
|
+
transaction: [],
|
|
54
|
+
serializers: [],
|
|
55
|
+
supportedLanguages: ["en"],
|
|
56
|
+
defaultLanguage: "en",
|
|
57
|
+
},
|
|
58
|
+
folders: {
|
|
59
|
+
root,
|
|
60
|
+
config: path_1.default.join(root, "Config"),
|
|
61
|
+
events: path_1.default.join(root, "Events"),
|
|
62
|
+
hooks: path_1.default.join(root, "Hooks"),
|
|
63
|
+
middlewares: path_1.default.join(root, "Middlewares"),
|
|
64
|
+
models: path_1.default.join(root, "Models"),
|
|
65
|
+
serialization: path_1.default.join(root, "Serialization"),
|
|
66
|
+
},
|
|
67
|
+
modelList: new ModelListService_1.default([]),
|
|
68
|
+
modelTree: [],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
getVersion(name) {
|
|
72
|
+
const version = this.folders.versions.find((i) => i.name === name);
|
|
73
|
+
if (!version) {
|
|
74
|
+
throw new Error(`Undefined version: ${version}`);
|
|
75
|
+
}
|
|
76
|
+
return version;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.default = APIService;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { IModelService, IRouteDocumentation } from "../Interfaces";
|
|
2
2
|
import { HttpMethods } from "../Enums";
|
|
3
3
|
declare class DocumentationService {
|
|
4
|
-
|
|
4
|
+
private static instance;
|
|
5
|
+
private routes;
|
|
5
6
|
constructor();
|
|
7
|
+
static getInstance(): DocumentationService;
|
|
6
8
|
push(method: HttpMethods, url: string, model: IModelService): void;
|
|
7
9
|
get(): IRouteDocumentation[];
|
|
8
10
|
}
|
|
@@ -4,6 +4,12 @@ class DocumentationService {
|
|
|
4
4
|
constructor() {
|
|
5
5
|
this.routes = [];
|
|
6
6
|
}
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!DocumentationService.instance) {
|
|
9
|
+
DocumentationService.instance = new DocumentationService();
|
|
10
|
+
}
|
|
11
|
+
return DocumentationService.instance;
|
|
12
|
+
}
|
|
7
13
|
push(method, url, model) {
|
|
8
14
|
this.routes.push({
|
|
9
15
|
model: model.name,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { LogLevels } from "../Enums";
|
|
2
2
|
declare class LogService {
|
|
3
|
-
|
|
3
|
+
private static instance;
|
|
4
|
+
private level;
|
|
4
5
|
constructor(level: LogLevels);
|
|
6
|
+
static setInstance(level: LogLevels): void;
|
|
7
|
+
static getInstance(): LogService;
|
|
5
8
|
error(message: string): void;
|
|
6
9
|
warn(message: string): void;
|
|
7
10
|
info(message: string): void;
|
|
@@ -7,6 +7,12 @@ class LogService {
|
|
|
7
7
|
constructor(level) {
|
|
8
8
|
this.level = level;
|
|
9
9
|
}
|
|
10
|
+
static setInstance(level) {
|
|
11
|
+
LogService.instance = new LogService(level);
|
|
12
|
+
}
|
|
13
|
+
static getInstance() {
|
|
14
|
+
return LogService.instance;
|
|
15
|
+
}
|
|
10
16
|
error(message) {
|
|
11
17
|
if (this.level >= Enums_1.LogLevels.ERROR) {
|
|
12
18
|
console.error(fgRed, "[axe]", message, fgReset);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HookFunctionTypes, Extensions } from "../Enums";
|
|
2
2
|
import { IColumn, IHookParameter, IModelService, IRelation } from "../Interfaces";
|
|
3
3
|
import Model from "./../Model";
|
|
4
|
+
import { SerializationFunction } from "../Types";
|
|
4
5
|
declare class ModelService implements IModelService {
|
|
5
6
|
name: string;
|
|
6
7
|
instance: Model;
|
|
@@ -11,9 +12,11 @@ declare class ModelService implements IModelService {
|
|
|
11
12
|
events: Record<HookFunctionTypes, (params: IHookParameter) => void>;
|
|
12
13
|
children: IModelService[];
|
|
13
14
|
isRecursive: boolean;
|
|
15
|
+
serialize: SerializationFunction | null;
|
|
14
16
|
constructor(name: string, instance: Model);
|
|
15
17
|
setColumns(columns: IColumn[]): void;
|
|
16
18
|
setExtensions(type: Extensions, hookFunctionType: HookFunctionTypes, data: (params: IHookParameter) => void): void;
|
|
19
|
+
setSerialization(callback: SerializationFunction): void;
|
|
17
20
|
private setHooks;
|
|
18
21
|
private setEvents;
|
|
19
22
|
}
|
|
@@ -12,6 +12,7 @@ class ModelService {
|
|
|
12
12
|
this.columnNames = [];
|
|
13
13
|
this.children = [];
|
|
14
14
|
this.isRecursive = false;
|
|
15
|
+
this.serialize = null;
|
|
15
16
|
}
|
|
16
17
|
setColumns(columns) {
|
|
17
18
|
this.columns = columns;
|
|
@@ -28,6 +29,9 @@ class ModelService {
|
|
|
28
29
|
throw new Error("Undefined hook type.");
|
|
29
30
|
}
|
|
30
31
|
}
|
|
32
|
+
setSerialization(callback) {
|
|
33
|
+
this.serialize = callback;
|
|
34
|
+
}
|
|
31
35
|
setHooks(hookFunctionType, data) {
|
|
32
36
|
this.hooks[hookFunctionType] = data;
|
|
33
37
|
}
|
|
@@ -175,6 +175,9 @@ class QueryService {
|
|
|
175
175
|
sort: this.parseSortingOptions(sections.sort),
|
|
176
176
|
q: this.parseCondition(sections.q),
|
|
177
177
|
with: withQueryResolver.resolve((sections === null || sections === void 0 ? void 0 : sections.with) || ""),
|
|
178
|
+
trashed: (sections === null || sections === void 0 ? void 0 : sections.trashed)
|
|
179
|
+
? sections.trashed.trim() === "true" || sections.trashed.trim() === "1"
|
|
180
|
+
: false,
|
|
178
181
|
};
|
|
179
182
|
this.addRelationColumns(query.with);
|
|
180
183
|
return query;
|
|
@@ -8,11 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const AxeError_1 = __importDefault(require("../Exceptions/AxeError"));
|
|
12
16
|
const Enums_1 = require("../Enums");
|
|
13
17
|
const Services_1 = require("../Services");
|
|
14
18
|
class SchemaValidatorService {
|
|
15
|
-
constructor() {
|
|
19
|
+
constructor(version) {
|
|
16
20
|
this.getModelFillableColumns = (model) => {
|
|
17
21
|
const fillable = model.instance.fillable;
|
|
18
22
|
if (!fillable) {
|
|
@@ -57,36 +61,39 @@ class SchemaValidatorService {
|
|
|
57
61
|
if (model.instance.updatedAtColumn) {
|
|
58
62
|
columns.push(model.instance.updatedAtColumn);
|
|
59
63
|
}
|
|
64
|
+
if (model.instance.deletedAtColumn) {
|
|
65
|
+
columns.push(model.instance.deletedAtColumn);
|
|
66
|
+
}
|
|
60
67
|
return columns;
|
|
61
68
|
};
|
|
62
69
|
this.checkHasManyRelation = (modelList, model, relation) => {
|
|
63
70
|
this.checkModelColumnsOrFail(model, [relation.primaryKey]);
|
|
64
71
|
const relatedModel = modelList.find(relation.model);
|
|
65
72
|
if (!relatedModel) {
|
|
66
|
-
throw new
|
|
73
|
+
throw new AxeError_1.default(Enums_1.AxeErrorCode.UNDEFINED_RELATION_MODEL, `Undefined related model: ${relation.model} (${model.name}.${relation.name})`);
|
|
67
74
|
}
|
|
68
75
|
this.checkModelColumnsOrFail(relatedModel, [relation.foreignKey]);
|
|
69
76
|
};
|
|
77
|
+
this.version = version;
|
|
70
78
|
}
|
|
71
79
|
validate() {
|
|
72
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const logger =
|
|
74
|
-
|
|
75
|
-
modelList.get().forEach((model) => {
|
|
81
|
+
const logger = Services_1.LogService.getInstance();
|
|
82
|
+
this.version.modelList.get().forEach((model) => {
|
|
76
83
|
this.checkModelColumnsOrFail(model, this.getModelFillableColumns(model));
|
|
77
84
|
this.checkModelColumnsOrFail(model, this.getModelFormValidationColumns(model));
|
|
78
85
|
this.checkModelColumnsOrFail(model, this.getModelHiddenColumns(model));
|
|
79
86
|
this.checkModelColumnsOrFail(model, this.getTimestampsColumns(model));
|
|
80
87
|
this.checkModelColumnsOrFail(model, [model.instance.primaryKey]);
|
|
81
|
-
this.checkRelationColumnsOrFail(modelList, model);
|
|
88
|
+
this.checkRelationColumnsOrFail(this.version.modelList, model);
|
|
82
89
|
});
|
|
83
|
-
logger.info(
|
|
90
|
+
logger.info(`[${this.version.name}] Database schema has been validated.`);
|
|
84
91
|
});
|
|
85
92
|
}
|
|
86
93
|
checkModelColumnsOrFail(model, modelColumns) {
|
|
87
94
|
const undefinedColumns = modelColumns.filter((modelColumn) => !model.columnNames.includes(modelColumn));
|
|
88
95
|
if (undefinedColumns.length > 0) {
|
|
89
|
-
throw new
|
|
96
|
+
throw new AxeError_1.default(Enums_1.AxeErrorCode.UNDEFINED_COLUMN, `${model.name} model doesn't have the following columns on the database; "${model.instance.table}.${undefinedColumns.join(",")}"`);
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
99
|
checkRelationColumnsOrFail(modelList, model) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import APIService from "./APIService";
|
|
1
2
|
import DocumentationService from "./DocumentationService";
|
|
2
3
|
import IoCService from "./IoCService";
|
|
3
4
|
import LogService from "./LogService";
|
|
@@ -5,4 +6,4 @@ import ModelListService from "./ModelListService";
|
|
|
5
6
|
import ModelService from "./ModelService";
|
|
6
7
|
import QueryService from "./QueryService";
|
|
7
8
|
import SchemaValidatorService from "./SchemaValidatorService";
|
|
8
|
-
export { DocumentationService, IoCService, LogService, ModelListService, ModelService, QueryService, SchemaValidatorService, };
|
|
9
|
+
export { DocumentationService, APIService, IoCService, LogService, ModelListService, ModelService, QueryService, SchemaValidatorService, };
|
|
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SchemaValidatorService = exports.QueryService = exports.ModelService = exports.ModelListService = exports.LogService = exports.IoCService = exports.DocumentationService = void 0;
|
|
6
|
+
exports.SchemaValidatorService = exports.QueryService = exports.ModelService = exports.ModelListService = exports.LogService = exports.IoCService = exports.APIService = exports.DocumentationService = void 0;
|
|
7
|
+
const APIService_1 = __importDefault(require("./APIService"));
|
|
8
|
+
exports.APIService = APIService_1.default;
|
|
7
9
|
const DocumentationService_1 = __importDefault(require("./DocumentationService"));
|
|
8
10
|
exports.DocumentationService = DocumentationService_1.default;
|
|
9
11
|
const IoCService_1 = __importDefault(require("./IoCService"));
|
package/build/src/constants.d.ts
CHANGED
|
@@ -20,4 +20,5 @@ export declare const API_ROUTE_TEMPLATES: {
|
|
|
20
20
|
update: (prefix: string, parentUrl: string, resource: string, primaryKey: string) => string;
|
|
21
21
|
patch: (prefix: string, parentUrl: string, resource: string, primaryKey: string) => string;
|
|
22
22
|
destroy: (prefix: string, parentUrl: string, resource: string, primaryKey: string) => string;
|
|
23
|
+
force_delete: (prefix: string, parentUrl: string, resource: string, primaryKey: string) => string;
|
|
23
24
|
};
|
package/build/src/constants.js
CHANGED
|
@@ -26,7 +26,6 @@ exports.DEFAULT_METHODS_OF_MODELS = [
|
|
|
26
26
|
"hasMany",
|
|
27
27
|
"hasOne",
|
|
28
28
|
"belongsTo",
|
|
29
|
-
"serialize",
|
|
30
29
|
"__defineGetter__",
|
|
31
30
|
"__defineSetter__",
|
|
32
31
|
"hasOwnProperty",
|
|
@@ -46,6 +45,7 @@ exports.DEFAULT_METHODS_OF_MODELS = [
|
|
|
46
45
|
"hiddens",
|
|
47
46
|
"createdAtColumn",
|
|
48
47
|
"updatedAtColumn",
|
|
48
|
+
"deletedAtColumn",
|
|
49
49
|
"transaction",
|
|
50
50
|
"ignore",
|
|
51
51
|
"getFillableFields",
|
|
@@ -59,4 +59,5 @@ exports.API_ROUTE_TEMPLATES = {
|
|
|
59
59
|
[Enums_1.HandlerTypes.UPDATE]: (prefix, parentUrl, resource, primaryKey) => `/${prefix}/${parentUrl}${resource}/:${primaryKey}`,
|
|
60
60
|
[Enums_1.HandlerTypes.PATCH]: (prefix, parentUrl, resource, primaryKey) => `/${prefix}/${parentUrl}${resource}/:${primaryKey}`,
|
|
61
61
|
[Enums_1.HandlerTypes.DELETE]: (prefix, parentUrl, resource, primaryKey) => `/${prefix}/${parentUrl}${resource}/:${primaryKey}`,
|
|
62
|
+
[Enums_1.HandlerTypes.FORCE_DELETE]: (prefix, parentUrl, resource, primaryKey) => `/${prefix}/${parentUrl}${resource}/:${primaryKey}/force`,
|
|
62
63
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axe-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0-rc1",
|
|
4
4
|
"description": "AXE API is a simple tool which has been created based on Express and Knex.js to create Rest APIs quickly.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@types/express": "^4.17.15",
|
|
33
|
+
"chalk": "^4.1.2",
|
|
33
34
|
"change-case": "^4.1.2",
|
|
34
35
|
"dotenv": "^14.2.0",
|
|
35
36
|
"express": "^4.18.2",
|
package/readme.md
CHANGED
|
@@ -145,30 +145,6 @@ If you can see that response, it means that your project is running properly.
|
|
|
145
145
|
|
|
146
146
|
Axe API has great documentation. Please [check it out in here](https://axe-api.com/).
|
|
147
147
|
|
|
148
|
-
## How To Run Integration Tests
|
|
149
|
-
|
|
150
|
-
> You have to have **Docker** and **Docker Compose** on your local development environment to run integration tests.
|
|
151
|
-
|
|
152
|
-
Execute the following commands to prepare the integration app
|
|
153
|
-
|
|
154
|
-
```sh
|
|
155
|
-
cd tests/integrations && npm install && npm ci && npm run build --if-present
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
Execute the following commands to prepare the database;
|
|
159
|
-
|
|
160
|
-
```sh
|
|
161
|
-
docker-compose -f "./tests/integrations/docker-compose.mysql8.yml" up -d --build
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
> To down the database, you can use the following command; `docker-compose -f "./tests/integrations/docker-compose.mysql8.yml" up -d --build`
|
|
165
|
-
|
|
166
|
-
You can execute the following command to execute tests;
|
|
167
|
-
|
|
168
|
-
```sh
|
|
169
|
-
npm run test:integration:mysql8
|
|
170
|
-
```
|
|
171
|
-
|
|
172
148
|
## License
|
|
173
149
|
|
|
174
150
|
[MIT License](LICENSE)
|