axe-api 1.2.0 → 1.3.0
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.
|
@@ -55,8 +55,8 @@ class RouterBuilder {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
createRouteByModel(
|
|
59
|
-
return __awaiter(this,
|
|
58
|
+
createRouteByModel(model_1) {
|
|
59
|
+
return __awaiter(this, arguments, void 0, function* (model, parentPairs = [], urlPrefix = "", parentModel = null, relation = null, allowRecursive = true) {
|
|
60
60
|
if (model.instance.ignore) {
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
@@ -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) {
|
|
@@ -143,9 +166,29 @@ class ModelResolver {
|
|
|
143
166
|
if (!currentModel) {
|
|
144
167
|
throw new AxeError_1.default(Enums_1.AxeErrorCode.UNDEFINED_HOOK_MODEL_RELATION, `Undefined model relation: ${subfolderPath}`);
|
|
145
168
|
}
|
|
169
|
+
// Loading hooks via index.ts if there is any
|
|
170
|
+
const indexFilePath = path_1.default.join(subfolderPath, "index.ts");
|
|
171
|
+
if (fs_1.default.existsSync(indexFilePath)) {
|
|
172
|
+
// Importing the file
|
|
173
|
+
const content = yield Promise.resolve(`${indexFilePath}`).then(s => __importStar(require(s)));
|
|
174
|
+
const keys = Object.keys(content);
|
|
175
|
+
for (const key of keys) {
|
|
176
|
+
// The exported function should be a hook function
|
|
177
|
+
if (hookList.includes(key)) {
|
|
178
|
+
currentModel.setExtensions(hookType, key, content[key]);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
Services_1.LogService.warn(`Invalid ${hookType} function: "${key}()" in the index.ts: "${indexFilePath}"`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
146
185
|
// Loading all hooks files in the subfolder
|
|
147
186
|
const hooks = yield fileResolver.resolveContent(subfolderPath);
|
|
148
187
|
for (const hookName in hooks) {
|
|
188
|
+
// We can ignore the index.ts
|
|
189
|
+
if (hookName === "index") {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
149
192
|
// If we have an acceptable hook
|
|
150
193
|
if (hookList.includes(hookName)) {
|
|
151
194
|
// We bind the hook with the model
|
package/build/src/Server.js
CHANGED
|
@@ -138,8 +138,8 @@ class Server {
|
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
listen() {
|
|
141
|
-
var _a;
|
|
142
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
var _a;
|
|
143
143
|
const app = yield Services_1.IoCService.use("App");
|
|
144
144
|
const api = Services_1.APIService.getInstance();
|
|
145
145
|
// Adding the default handler for auto-created routes
|
|
@@ -109,8 +109,8 @@ class AxeRequest {
|
|
|
109
109
|
* @returns
|
|
110
110
|
*/
|
|
111
111
|
files(options) {
|
|
112
|
-
var _a, _b;
|
|
113
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
var _a, _b;
|
|
114
114
|
if (!((_a = this.header("content-type")) === null || _a === void 0 ? void 0 : _a.includes("multipart/form-data"))) {
|
|
115
115
|
LogService_1.default.warn(`Content-type must be 'multipart/form-data'.`);
|
|
116
116
|
throw new Error(`Content-type must be 'multipart/form-data'.`);
|
|
@@ -48,9 +48,15 @@ class ModelService {
|
|
|
48
48
|
this.children = [];
|
|
49
49
|
}
|
|
50
50
|
setHooks(hookFunctionType, data) {
|
|
51
|
+
if (this.hooks[hookFunctionType]) {
|
|
52
|
+
throw new Error(`You can define only one hook function: ${this.name}.${hookFunctionType}`);
|
|
53
|
+
}
|
|
51
54
|
this.hooks[hookFunctionType] = data;
|
|
52
55
|
}
|
|
53
56
|
setEvents(hookFunctionType, data) {
|
|
57
|
+
if (this.events[hookFunctionType]) {
|
|
58
|
+
throw new Error(`You can define only one event function: ${this.name}.${hookFunctionType}`);
|
|
59
|
+
}
|
|
54
60
|
this.events[hookFunctionType] = data;
|
|
55
61
|
}
|
|
56
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axe-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "AXE API is a simple tool to create Rest APIs quickly.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"knex-schema-inspector": "^3.1.0",
|
|
68
68
|
"nanoid": "^3.3.7",
|
|
69
69
|
"pino": "^8.18.0",
|
|
70
|
-
"pino-pretty": "^
|
|
70
|
+
"pino-pretty": "^11.0.0",
|
|
71
71
|
"pluralize": "^8.0.0",
|
|
72
72
|
"validatorjs": "^3.22.1"
|
|
73
73
|
},
|
|
@@ -101,7 +101,6 @@
|
|
|
101
101
|
"multer": "^1.4.5-lts.1",
|
|
102
102
|
"mysql": "^2.18.1",
|
|
103
103
|
"node-cache": "^5.1.2",
|
|
104
|
-
"node-color-log": "^11.0.2",
|
|
105
104
|
"nodemon": "^3.0.3",
|
|
106
105
|
"pg": "^8.11.3",
|
|
107
106
|
"prettier": "^3.2.5",
|