axe-api 1.1.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
|
}
|
|
@@ -181,13 +181,105 @@ export interface IContext extends IRouteData {
|
|
|
181
181
|
isTransactionOpen: boolean;
|
|
182
182
|
validator: IValidator;
|
|
183
183
|
queryParser?: QueryService;
|
|
184
|
+
params?: any;
|
|
185
|
+
/**
|
|
186
|
+
* @deprecated Use special hook type instead of IContext like IBeforeInsertContext
|
|
187
|
+
*/
|
|
184
188
|
conditions?: IQuery;
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated Use special hook type instead of IContext like IBeforeInsertContext
|
|
191
|
+
*/
|
|
185
192
|
query?: Knex.QueryBuilder;
|
|
186
|
-
|
|
193
|
+
/**
|
|
194
|
+
* @deprecated Use special hook type instead of IContext like IBeforeInsertContext
|
|
195
|
+
*/
|
|
187
196
|
result?: any;
|
|
197
|
+
/**
|
|
198
|
+
* @deprecated Use special hook type instead of IContext like IBeforeInsertContext
|
|
199
|
+
*/
|
|
188
200
|
item?: any;
|
|
201
|
+
/**
|
|
202
|
+
* @deprecated Use special hook type instead of IContext like IBeforeInsertContext
|
|
203
|
+
*/
|
|
189
204
|
formData?: any;
|
|
190
205
|
}
|
|
206
|
+
export interface IBeforeInsertContext extends IContext {
|
|
207
|
+
formData: any;
|
|
208
|
+
}
|
|
209
|
+
export interface IBeforeUpdateQueryContext extends IContext {
|
|
210
|
+
query: Knex.QueryBuilder;
|
|
211
|
+
}
|
|
212
|
+
export interface IBeforeUpdateContext extends IContext {
|
|
213
|
+
query: Knex.QueryBuilder;
|
|
214
|
+
item: any;
|
|
215
|
+
formData: any;
|
|
216
|
+
}
|
|
217
|
+
export interface IBeforeDeleteQueryContext extends IContext {
|
|
218
|
+
query: Knex.QueryBuilder;
|
|
219
|
+
}
|
|
220
|
+
export interface IBeforeDeleteContext extends IContext {
|
|
221
|
+
query: Knex.QueryBuilder;
|
|
222
|
+
}
|
|
223
|
+
export interface IBeforeForceDeleteQueryContext extends IContext {
|
|
224
|
+
query: Knex.QueryBuilder;
|
|
225
|
+
}
|
|
226
|
+
export interface IBeforeForceDeleteContext extends IContext {
|
|
227
|
+
query: Knex.QueryBuilder;
|
|
228
|
+
}
|
|
229
|
+
export interface IBeforePaginateContext extends IContext {
|
|
230
|
+
query: Knex.QueryBuilder;
|
|
231
|
+
conditions: IQuery;
|
|
232
|
+
}
|
|
233
|
+
export interface IBeforeAllContext extends IContext {
|
|
234
|
+
query: Knex.QueryBuilder;
|
|
235
|
+
conditions: IQuery;
|
|
236
|
+
}
|
|
237
|
+
export interface IBeforeShowContext extends IContext {
|
|
238
|
+
query: Knex.QueryBuilder;
|
|
239
|
+
conditions: IQuery;
|
|
240
|
+
}
|
|
241
|
+
export interface IAfterInsertContext extends IContext {
|
|
242
|
+
item: any;
|
|
243
|
+
formData: any;
|
|
244
|
+
}
|
|
245
|
+
export interface IAfterUpdateQueryContext extends IContext {
|
|
246
|
+
query: Knex.QueryBuilder;
|
|
247
|
+
item: any;
|
|
248
|
+
}
|
|
249
|
+
export interface IAfterUpdateContext extends IContext {
|
|
250
|
+
query: Knex.QueryBuilder;
|
|
251
|
+
item: any;
|
|
252
|
+
formData: any;
|
|
253
|
+
}
|
|
254
|
+
export interface IAfterDeleteQueryContext extends IContext {
|
|
255
|
+
query: Knex.QueryBuilder;
|
|
256
|
+
item: any;
|
|
257
|
+
}
|
|
258
|
+
export interface IAfterDeleteContext extends IContext {
|
|
259
|
+
item: any;
|
|
260
|
+
}
|
|
261
|
+
export interface IAfterForceDeleteQueryContext extends IContext {
|
|
262
|
+
query: Knex.QueryBuilder;
|
|
263
|
+
item: any;
|
|
264
|
+
}
|
|
265
|
+
export interface IAfterForceDeleteContext extends IContext {
|
|
266
|
+
item: any;
|
|
267
|
+
}
|
|
268
|
+
export interface IAfterPaginateContext extends IContext {
|
|
269
|
+
query: Knex.QueryBuilder;
|
|
270
|
+
conditions: IQuery;
|
|
271
|
+
result: any;
|
|
272
|
+
}
|
|
273
|
+
export interface IAfterAllContext extends IContext {
|
|
274
|
+
query: Knex.QueryBuilder;
|
|
275
|
+
conditions: IQuery;
|
|
276
|
+
result: any;
|
|
277
|
+
}
|
|
278
|
+
export interface IAfterShowContext extends IContext {
|
|
279
|
+
query: Knex.QueryBuilder;
|
|
280
|
+
conditions: IQuery;
|
|
281
|
+
item: any;
|
|
282
|
+
}
|
|
191
283
|
export interface IRouteDocumentation {
|
|
192
284
|
version: string;
|
|
193
285
|
handler: string;
|
|
@@ -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
|
|
@@ -191,9 +234,22 @@ class ModelResolver {
|
|
|
191
234
|
const fileResolver = new FileResolver_1.default();
|
|
192
235
|
const serializations = yield fileResolver.resolveContent(this.version.folders.serialization);
|
|
193
236
|
for (const model of modelList.get()) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
237
|
+
// Old serialization
|
|
238
|
+
const oldName = `${model.name}Serialization`;
|
|
239
|
+
let isOldNamingUsed = false;
|
|
240
|
+
if (serializations[oldName]) {
|
|
241
|
+
isOldNamingUsed = true;
|
|
242
|
+
const file = serializations[oldName];
|
|
243
|
+
model.setSerialization(file.default);
|
|
244
|
+
Services_1.LogService.warn(`'${oldName}.ts' naming is deprecated. You can use '${oldName.replace("Serialization", "")}.ts' instead.`);
|
|
245
|
+
}
|
|
246
|
+
// New
|
|
247
|
+
const newName = `${model.name}`;
|
|
248
|
+
if (serializations[newName]) {
|
|
249
|
+
if (isOldNamingUsed) {
|
|
250
|
+
throw new Error(`You cannot use '${oldName}.ts' and '${newName}.ts' at the same time.`);
|
|
251
|
+
}
|
|
252
|
+
const file = serializations[newName];
|
|
197
253
|
model.setSerialization(file.default);
|
|
198
254
|
}
|
|
199
255
|
}
|
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",
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "rm -rf build && tsc && rm -rf build/dev-kit",
|
|
31
31
|
"build:watch": "tsc -w",
|
|
32
|
-
"dev": "
|
|
33
|
-
"dev-kit": "ts-node-dev --respawn --clear dev-kit.ts",
|
|
32
|
+
"dev-kit": "tsx watch dev-kit.ts",
|
|
34
33
|
"dev-kit:install": "node ./scripts/dev-kit-install.js",
|
|
35
34
|
"dev-kit:remove": "node ./scripts/dev-kit-remove.js",
|
|
36
35
|
"test": "jest --runInBand",
|
|
@@ -68,7 +67,7 @@
|
|
|
68
67
|
"knex-schema-inspector": "^3.1.0",
|
|
69
68
|
"nanoid": "^3.3.7",
|
|
70
69
|
"pino": "^8.18.0",
|
|
71
|
-
"pino-pretty": "^
|
|
70
|
+
"pino-pretty": "^11.0.0",
|
|
72
71
|
"pluralize": "^8.0.0",
|
|
73
72
|
"validatorjs": "^3.22.1"
|
|
74
73
|
},
|
|
@@ -102,18 +101,17 @@
|
|
|
102
101
|
"multer": "^1.4.5-lts.1",
|
|
103
102
|
"mysql": "^2.18.1",
|
|
104
103
|
"node-cache": "^5.1.2",
|
|
105
|
-
"node-color-log": "^11.0.2",
|
|
106
104
|
"nodemon": "^3.0.3",
|
|
107
105
|
"pg": "^8.11.3",
|
|
108
106
|
"prettier": "^3.2.5",
|
|
109
107
|
"redis": "^4.6.13",
|
|
108
|
+
"robust-validator": "^1.1.0",
|
|
110
109
|
"serve-static": "^1.15.0",
|
|
111
110
|
"set-value": ">=4.1.0",
|
|
112
111
|
"sqlite3": "^5.1.7",
|
|
113
112
|
"ts-node": "^10.9.2",
|
|
114
|
-
"
|
|
115
|
-
"typescript": "^5.3.3"
|
|
116
|
-
"robust-validator": "^1.1.0"
|
|
113
|
+
"tsx": "^4.7.1",
|
|
114
|
+
"typescript": "^5.3.3"
|
|
117
115
|
},
|
|
118
116
|
"lint-staged": {
|
|
119
117
|
"**/*": "prettier --write --ignore-unknown"
|