axe-api 1.0.0-rc8 → 1.0.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.
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/src/Builders/IndexBuilder.d.ts +7 -0
- package/build/src/Builders/IndexBuilder.js +35 -0
- package/build/src/Builders/ModelTreeBuilder.js +2 -1
- package/build/src/Builders/RouterBuilder.js +22 -11
- package/build/src/Builders/SwaggerBuilder.d.ts +2 -0
- package/build/src/Builders/SwaggerBuilder.js +609 -0
- package/build/src/Enums.d.ts +6 -1
- package/build/src/Enums.js +7 -1
- package/build/src/Handlers/DocsHandler.js +41 -0
- package/build/src/Handlers/ErrorHandler.d.ts +6 -0
- package/build/src/Handlers/ErrorHandler.js +12 -0
- package/build/src/Handlers/Helpers.d.ts +16 -4
- package/build/src/Handlers/Helpers.js +202 -5
- package/build/src/Handlers/RequestHandler.d.ts +4 -1
- package/build/src/Handlers/RequestHandler.js +36 -40
- package/build/src/Handlers/{DocsHTMLHandler.js → SwaggerHandler.js} +8 -7
- package/build/src/Interfaces.d.ts +103 -35
- package/build/src/Middlewares/RateLimit/AdaptorFactory.d.ts +3 -3
- package/build/src/Middlewares/RateLimit/MemoryAdaptor.d.ts +2 -2
- package/build/src/Middlewares/RateLimit/RedisAdaptor.d.ts +12 -4
- package/build/src/Middlewares/RateLimit/RedisAdaptor.js +24 -0
- package/build/src/Middlewares/RateLimit/index.d.ts +22 -3
- package/build/src/Middlewares/RateLimit/index.js +23 -3
- package/build/src/Model.d.ts +256 -10
- package/build/src/Model.js +322 -30
- package/build/src/Phases/All/FetchPhase.d.ts +2 -2
- package/build/src/Phases/All/PreparePhase.d.ts +2 -2
- package/build/src/Phases/All/index.d.ts +1 -1
- package/build/src/Phases/CacheTagCleanPhase.d.ts +3 -0
- package/build/src/{Handlers/MetadataHandler.js → Phases/CacheTagCleanPhase.js} +6 -10
- package/build/src/Phases/Delete/ActionPhase.d.ts +2 -2
- package/build/src/Phases/Delete/ActionPhase.js +21 -2
- package/build/src/Phases/Delete/PreparePhase.d.ts +2 -2
- package/build/src/Phases/Delete/QueryPhase.d.ts +2 -2
- package/build/src/Phases/Delete/ResponsePhase.d.ts +2 -2
- package/build/src/Phases/Delete/ResponsePhase.js +2 -1
- package/build/src/Phases/Delete/index.d.ts +4 -4
- package/build/src/Phases/ForceDelete/ActionPhase.d.ts +2 -2
- package/build/src/Phases/ForceDelete/ActionPhase.js +7 -0
- package/build/src/Phases/ForceDelete/PreparePhase.d.ts +2 -2
- package/build/src/Phases/ForceDelete/QueryPhase.d.ts +2 -2
- package/build/src/Phases/ForceDelete/index.d.ts +3 -3
- package/build/src/Phases/GetCachePhase.d.ts +3 -0
- package/build/src/Phases/GetCachePhase.js +39 -0
- package/build/src/Phases/List/RelationalPhase.d.ts +2 -2
- package/build/src/Phases/List/ResultPhase.d.ts +2 -2
- package/build/src/Phases/List/ResultPhase.js +9 -1
- package/build/src/Phases/List/SerializePhase.d.ts +2 -2
- package/build/src/Phases/List/index.d.ts +3 -3
- package/build/src/Phases/Paginate/FetchPhase.d.ts +2 -2
- package/build/src/Phases/Paginate/FetchPhase.js +11 -0
- package/build/src/Phases/Paginate/PreparePhase.d.ts +2 -2
- package/build/src/Phases/Paginate/PreparePhase.js +0 -8
- package/build/src/Phases/Paginate/index.d.ts +2 -2
- package/build/src/Phases/Patch/PrepareActionPhase.d.ts +2 -2
- package/build/src/Phases/Patch/PrepareActionPhase.js +13 -10
- package/build/src/Phases/Patch/index.d.ts +1 -1
- package/build/src/Phases/Search/FetchPhase.d.ts +3 -0
- package/build/src/Phases/Search/FetchPhase.js +66 -0
- package/build/src/Phases/Search/PreparePhase.d.ts +3 -0
- package/build/src/Phases/Search/PreparePhase.js +19 -0
- package/build/src/Phases/Search/index.d.ts +5 -0
- package/build/src/Phases/Search/index.js +11 -0
- package/build/src/Phases/Show/FetchPhase.d.ts +2 -2
- package/build/src/Phases/Show/FetchPhase.js +11 -1
- package/build/src/Phases/Show/PreparePhase.d.ts +2 -2
- package/build/src/Phases/Show/PreparePhase.js +5 -13
- package/build/src/Phases/Show/index.d.ts +2 -2
- package/build/src/Phases/Single/GetPhase.d.ts +2 -2
- package/build/src/Phases/Single/PrepareGetPhase.d.ts +2 -2
- package/build/src/Phases/Single/RelationalPhase.d.ts +2 -2
- package/build/src/Phases/Single/ResultPhase.d.ts +2 -2
- package/build/src/Phases/Single/ResultPhase.js +9 -1
- package/build/src/Phases/Single/SerializePhase.d.ts +2 -2
- package/build/src/Phases/Single/index.d.ts +5 -5
- package/build/src/Phases/Store/ActionPhase.d.ts +2 -2
- package/build/src/Phases/Store/ActionPhase.js +18 -7
- package/build/src/Phases/Store/PreparePhase.d.ts +2 -2
- package/build/src/Phases/Store/PreparePhase.js +14 -9
- package/build/src/Phases/Store/ResultPhase.d.ts +3 -0
- package/build/src/Phases/Store/ResultPhase.js +23 -0
- package/build/src/Phases/Store/index.d.ts +3 -2
- package/build/src/Phases/Store/index.js +2 -0
- package/build/src/Phases/URLSearchParamPhase.d.ts +3 -0
- package/build/src/Phases/URLSearchParamPhase.js +37 -0
- package/build/src/Phases/Update/ActionPhase.d.ts +2 -2
- package/build/src/Phases/Update/ActionPhase.js +14 -3
- package/build/src/Phases/Update/PrepareActionPhase.d.ts +2 -2
- package/build/src/Phases/Update/PrepareActionPhase.js +13 -10
- package/build/src/Phases/Update/index.d.ts +2 -2
- package/build/src/Resolvers/ModelResolver.d.ts +1 -0
- package/build/src/Resolvers/ModelResolver.js +21 -2
- package/build/src/Resolvers/TransactionResolver.js +3 -15
- package/build/src/Resolvers/VersionConfigResolver.js +6 -1
- package/build/src/Resolvers/VersionResolver.js +1 -0
- package/build/src/Server.d.ts +5 -0
- package/build/src/Server.js +44 -11
- package/build/src/Services/APIService.d.ts +3 -3
- package/build/src/Services/APIService.js +3 -16
- package/build/src/Services/App.d.ts +94 -8
- package/build/src/Services/App.js +94 -29
- package/build/src/Services/AxeRequest.d.ts +51 -2
- package/build/src/Services/AxeRequest.js +51 -4
- package/build/src/Services/AxeResponse.d.ts +28 -1
- package/build/src/Services/AxeResponse.js +28 -0
- package/build/src/Services/ConverterService.d.ts +5 -3
- package/build/src/Services/DocumentationService.d.ts +5 -2
- package/build/src/Services/DocumentationService.js +13 -1
- package/build/src/Services/ElasticService.d.ts +14 -0
- package/build/src/Services/ElasticService.js +74 -0
- package/build/src/Services/IoCService.d.ts +29 -2
- package/build/src/Services/IoCService.js +33 -6
- package/build/src/Services/LimitService.d.ts +18 -0
- package/build/src/Services/LimitService.js +18 -0
- package/build/src/Services/ModelService.d.ts +9 -5
- package/build/src/Services/ModelService.js +11 -0
- package/build/src/Services/QueryService.d.ts +3 -3
- package/build/src/Services/QueryService.js +6 -0
- package/build/src/Services/SchemaValidatorService.d.ts +1 -0
- package/build/src/Services/SchemaValidatorService.js +4 -0
- package/build/src/Services/URLService.d.ts +6 -14
- package/build/src/Services/URLService.js +10 -8
- package/build/src/Steps/Event.d.ts +11 -0
- package/build/src/Steps/Event.js +17 -0
- package/build/src/Steps/Hook.d.ts +11 -0
- package/build/src/Steps/Hook.js +17 -0
- package/build/src/Steps/Phase.d.ts +11 -0
- package/build/src/Steps/Phase.js +18 -0
- package/build/src/Types.d.ts +12 -10
- package/build/src/constants.d.ts +8 -9
- package/build/src/constants.js +215 -152
- package/package.json +46 -36
- package/build/src/Middlewares/RateLimit/IAdaptor.d.ts +0 -6
- package/build/src/Middlewares/RateLimit/IAdaptor.js +0 -2
- /package/build/src/Handlers/{DocsHTMLHandler.d.ts → DocsHandler.d.ts} +0 -0
- /package/build/src/Handlers/{MetadataHandler.d.ts → SwaggerHandler.d.ts} +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
const elasticsearch_1 = require("@elastic/elasticsearch");
|
|
16
|
+
const LogService_1 = __importDefault(require("./LogService"));
|
|
17
|
+
class ElasticService {
|
|
18
|
+
constructor(config, options) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
this.client = new elasticsearch_1.Client(options);
|
|
21
|
+
LogService_1.default.debug("Elasticsearch connection has been completed.");
|
|
22
|
+
}
|
|
23
|
+
createIndex(modelName) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const index = this.toIndex(modelName);
|
|
26
|
+
const result = yield this.client.indices.exists({ index });
|
|
27
|
+
if (result === false) {
|
|
28
|
+
yield this.client.indices.create({ index });
|
|
29
|
+
LogService_1.default.debug(`ES.create({ index: ${index} })`);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
insert(modelName, id, body) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const index = this.toIndex(modelName);
|
|
36
|
+
const result = yield this.client.index({ index, id: id.toString(), body });
|
|
37
|
+
LogService_1.default.debug(`\t🔄 ES.insert(${index}) => ${id}`);
|
|
38
|
+
return result;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
update(modelName, id, doc) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const index = this.toIndex(modelName);
|
|
44
|
+
const result = yield this.client.update({ index, id: id.toString(), doc });
|
|
45
|
+
LogService_1.default.debug(`\t🔄 ES.update(${index}) => ${id}`);
|
|
46
|
+
return result;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
delete(modelName, id) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const index = this.toIndex(modelName);
|
|
52
|
+
const result = yield this.client.delete({ index, id: id.toString() });
|
|
53
|
+
LogService_1.default.debug(`\t🔄 ES.delete(${index}) => ${id}`);
|
|
54
|
+
return result;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
search(modelName, page, size, body) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const index = this.toIndex(modelName);
|
|
60
|
+
LogService_1.default.debug(`\t🔄 ES.search(${index}) => ${JSON.stringify(body)}`);
|
|
61
|
+
return yield this.client.search({
|
|
62
|
+
index,
|
|
63
|
+
body,
|
|
64
|
+
from: (page - 1) * size,
|
|
65
|
+
size,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
toIndex(modelName) {
|
|
70
|
+
const prefix = this.config.indexPrefix ? `${this.config.indexPrefix}-` : "";
|
|
71
|
+
return `${prefix}${modelName.toLowerCase()}`.trim();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.default = ElasticService;
|
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
declare class IoCService {
|
|
2
2
|
private static items;
|
|
3
|
+
/**
|
|
4
|
+
* Adding a dependency creator function.
|
|
5
|
+
*
|
|
6
|
+
* @param name
|
|
7
|
+
* @param callback
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* IoCService.bind("MailService", () => new MyMailService())
|
|
11
|
+
*/
|
|
3
12
|
static bind(name: string, callback: any): void;
|
|
13
|
+
/**
|
|
14
|
+
* Adding a singleton dependency creator function.
|
|
15
|
+
*
|
|
16
|
+
* @param name
|
|
17
|
+
* @param callback
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* IoCService.singleton("MySingleton", () => new MySingleton())
|
|
21
|
+
*/
|
|
4
22
|
static singleton(name: string, callback: any): void;
|
|
5
|
-
|
|
6
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Getting the service by the name.
|
|
25
|
+
*
|
|
26
|
+
* @param name
|
|
27
|
+
* @param callback
|
|
28
|
+
* @example
|
|
29
|
+
*
|
|
30
|
+
* await IoCService.use<MySingleton>("MySingleton")
|
|
31
|
+
*/
|
|
32
|
+
static use<T>(name: string): Promise<T>;
|
|
33
|
+
private static getByName;
|
|
7
34
|
private static _add;
|
|
8
35
|
}
|
|
9
36
|
export default IoCService;
|
|
@@ -11,13 +11,46 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const Enums_1 = require("../Enums");
|
|
13
13
|
class IoCService {
|
|
14
|
+
/**
|
|
15
|
+
* Adding a dependency creator function.
|
|
16
|
+
*
|
|
17
|
+
* @param name
|
|
18
|
+
* @param callback
|
|
19
|
+
* @example
|
|
20
|
+
*
|
|
21
|
+
* IoCService.bind("MailService", () => new MyMailService())
|
|
22
|
+
*/
|
|
14
23
|
static bind(name, callback) {
|
|
15
24
|
this._add(Enums_1.DependencyTypes.BIND, name, callback);
|
|
16
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Adding a singleton dependency creator function.
|
|
28
|
+
*
|
|
29
|
+
* @param name
|
|
30
|
+
* @param callback
|
|
31
|
+
* @example
|
|
32
|
+
*
|
|
33
|
+
* IoCService.singleton("MySingleton", () => new MySingleton())
|
|
34
|
+
*/
|
|
17
35
|
static singleton(name, callback) {
|
|
18
36
|
this._add(Enums_1.DependencyTypes.SINGLETON, name, callback);
|
|
19
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Getting the service by the name.
|
|
40
|
+
*
|
|
41
|
+
* @param name
|
|
42
|
+
* @param callback
|
|
43
|
+
* @example
|
|
44
|
+
*
|
|
45
|
+
* await IoCService.use<MySingleton>("MySingleton")
|
|
46
|
+
*/
|
|
20
47
|
static use(name) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const result = yield IoCService.getByName(name);
|
|
50
|
+
return result;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
static getByName(name) {
|
|
21
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
55
|
const item = IoCService.items[name];
|
|
23
56
|
if (!item) {
|
|
@@ -33,12 +66,6 @@ class IoCService {
|
|
|
33
66
|
return item.instance;
|
|
34
67
|
});
|
|
35
68
|
}
|
|
36
|
-
static useByType(name) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const result = yield IoCService.use(name);
|
|
39
|
-
return result;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
69
|
static _add(type, name, callback) {
|
|
43
70
|
IoCService.items[name] = {
|
|
44
71
|
type,
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { QueryFeature } from "../Enums";
|
|
2
2
|
import { IModelService, IQueryLimitConfig } from "../Interfaces";
|
|
3
|
+
/**
|
|
4
|
+
* Allow a query feature.
|
|
5
|
+
*
|
|
6
|
+
* @param feature
|
|
7
|
+
* @param keys
|
|
8
|
+
* @returns
|
|
9
|
+
* @example
|
|
10
|
+
* allow(QueryFeature.WhereLike)
|
|
11
|
+
*/
|
|
3
12
|
export declare const allow: (feature: QueryFeature, keys?: string[]) => IQueryLimitConfig[];
|
|
13
|
+
/**
|
|
14
|
+
* Deny a query feature.
|
|
15
|
+
*
|
|
16
|
+
* @param feature
|
|
17
|
+
* @param keys
|
|
18
|
+
* @returns
|
|
19
|
+
* @example
|
|
20
|
+
* deny(QueryFeature.WhereLike)
|
|
21
|
+
*/
|
|
4
22
|
export declare const deny: (feature: QueryFeature, keys?: string[]) => IQueryLimitConfig[];
|
|
5
23
|
export declare const valideteQueryFeature: (model: IModelService, feature: QueryFeature, key?: string | null, errorDescription?: string) => void;
|
|
@@ -84,10 +84,28 @@ const generatePermission = (type, feature, keys = []) => {
|
|
|
84
84
|
})
|
|
85
85
|
.flat();
|
|
86
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* Allow a query feature.
|
|
89
|
+
*
|
|
90
|
+
* @param feature
|
|
91
|
+
* @param keys
|
|
92
|
+
* @returns
|
|
93
|
+
* @example
|
|
94
|
+
* allow(QueryFeature.WhereLike)
|
|
95
|
+
*/
|
|
87
96
|
const allow = (feature, keys = []) => {
|
|
88
97
|
return generatePermission(Enums_1.QueryFeatureType.Allow, feature, keys);
|
|
89
98
|
};
|
|
90
99
|
exports.allow = allow;
|
|
100
|
+
/**
|
|
101
|
+
* Deny a query feature.
|
|
102
|
+
*
|
|
103
|
+
* @param feature
|
|
104
|
+
* @param keys
|
|
105
|
+
* @returns
|
|
106
|
+
* @example
|
|
107
|
+
* deny(QueryFeature.WhereLike)
|
|
108
|
+
*/
|
|
91
109
|
const deny = (feature, keys = []) => {
|
|
92
110
|
return generatePermission(Enums_1.QueryFeatureType.Deny, feature, keys);
|
|
93
111
|
};
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import { HookFunctionTypes, Extensions } from "../Enums";
|
|
2
|
-
import { IColumn, IModelService, IQueryLimitConfig, IRelation } from "../Interfaces";
|
|
1
|
+
import { HookFunctionTypes, Extensions, HandlerTypes } from "../Enums";
|
|
2
|
+
import { ICacheConfiguration, IColumn, IModelService, IQueryLimitConfig, IRelation } from "../Interfaces";
|
|
3
3
|
import Model from "./../Model";
|
|
4
|
-
import {
|
|
4
|
+
import { ModelHooks, PhaseFunction, SerializationFunction } from "../Types";
|
|
5
5
|
declare class ModelService implements IModelService {
|
|
6
6
|
name: string;
|
|
7
7
|
instance: Model;
|
|
8
8
|
relations: IRelation[];
|
|
9
9
|
columns: IColumn[];
|
|
10
10
|
columnNames: string[];
|
|
11
|
-
hooks:
|
|
12
|
-
events:
|
|
11
|
+
hooks: ModelHooks;
|
|
12
|
+
events: ModelHooks;
|
|
13
13
|
children: IModelService[];
|
|
14
14
|
isRecursive: boolean;
|
|
15
15
|
queryLimits: IQueryLimitConfig[];
|
|
16
16
|
serialize: SerializationFunction | null;
|
|
17
|
+
cacheConfiguration: Record<string, ICacheConfiguration>;
|
|
17
18
|
constructor(name: string, instance: Model);
|
|
18
19
|
setColumns(columns: IColumn[]): void;
|
|
20
|
+
setCacheConfiguration(handler: string, cache: ICacheConfiguration): void;
|
|
21
|
+
getCacheConfiguration(handler: HandlerTypes): ICacheConfiguration;
|
|
19
22
|
setExtensions(type: Extensions, hookFunctionType: HookFunctionTypes, data: PhaseFunction): void;
|
|
20
23
|
setQueryLimits(limits: IQueryLimitConfig[]): void;
|
|
21
24
|
setSerialization(callback: SerializationFunction): void;
|
|
25
|
+
setAsRecursive(): void;
|
|
22
26
|
private setHooks;
|
|
23
27
|
private setEvents;
|
|
24
28
|
}
|
|
@@ -14,11 +14,18 @@ class ModelService {
|
|
|
14
14
|
this.isRecursive = false;
|
|
15
15
|
this.queryLimits = [];
|
|
16
16
|
this.serialize = null;
|
|
17
|
+
this.cacheConfiguration = {};
|
|
17
18
|
}
|
|
18
19
|
setColumns(columns) {
|
|
19
20
|
this.columns = columns;
|
|
20
21
|
this.columnNames = this.columns.map((i) => i.name);
|
|
21
22
|
}
|
|
23
|
+
setCacheConfiguration(handler, cache) {
|
|
24
|
+
this.cacheConfiguration[handler] = cache;
|
|
25
|
+
}
|
|
26
|
+
getCacheConfiguration(handler) {
|
|
27
|
+
return this.cacheConfiguration[handler];
|
|
28
|
+
}
|
|
22
29
|
setExtensions(type, hookFunctionType, data) {
|
|
23
30
|
if (type == Enums_1.Extensions.Hooks) {
|
|
24
31
|
this.setHooks(hookFunctionType, data);
|
|
@@ -36,6 +43,10 @@ class ModelService {
|
|
|
36
43
|
setSerialization(callback) {
|
|
37
44
|
this.serialize = callback;
|
|
38
45
|
}
|
|
46
|
+
setAsRecursive() {
|
|
47
|
+
this.isRecursive = true;
|
|
48
|
+
this.children = [];
|
|
49
|
+
}
|
|
39
50
|
setHooks(hookFunctionType, data) {
|
|
40
51
|
this.hooks[hookFunctionType] = data;
|
|
41
52
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IQuery, ISortField, NestedWhere, IWhere, IModelService,
|
|
1
|
+
import { IQuery, ISortField, NestedWhere, IWhere, IModelService, AxeVersionConfig } from "../Interfaces";
|
|
2
2
|
import { Knex } from "knex";
|
|
3
3
|
declare class QueryService {
|
|
4
4
|
model: IModelService;
|
|
@@ -6,8 +6,8 @@ declare class QueryService {
|
|
|
6
6
|
usedConditionColumns: string[];
|
|
7
7
|
relationColumns: string[];
|
|
8
8
|
createdJoins: string[];
|
|
9
|
-
config:
|
|
10
|
-
constructor(model: IModelService, models: IModelService[], config:
|
|
9
|
+
config: AxeVersionConfig;
|
|
10
|
+
constructor(model: IModelService, models: IModelService[], config: AxeVersionConfig);
|
|
11
11
|
applyFields(query: Knex.QueryBuilder, fields: string[]): void;
|
|
12
12
|
applySorting(query: Knex.QueryBuilder, sort: ISortField[]): void;
|
|
13
13
|
applyWheresInsideGroup(sub: Knex.QueryBuilder, ruleSet: NestedWhere | IWhere): void;
|
|
@@ -184,6 +184,7 @@ class QueryService {
|
|
|
184
184
|
sort: this.parseSortingOptions(sections.get("sort")),
|
|
185
185
|
q: this.parseCondition(q),
|
|
186
186
|
with: withQueryResolver.resolve(sections.get("with") || ""),
|
|
187
|
+
text: sections.get("text") || null,
|
|
187
188
|
trashed: sections.get("trashed")
|
|
188
189
|
? (0, Helpers_1.isBoolean)(sections.get("trashed"))
|
|
189
190
|
: false,
|
|
@@ -331,6 +332,11 @@ class QueryService {
|
|
|
331
332
|
}
|
|
332
333
|
if (where.condition === Enums_1.ConditionTypes.LIKE ||
|
|
333
334
|
where.condition === Enums_1.ConditionTypes["NOT LIKE"]) {
|
|
335
|
+
const queryColumn = where.model.columns.find((column) => column.name === where.field);
|
|
336
|
+
if (queryColumn &&
|
|
337
|
+
!constants_1.STRING_COLUMN_TYPES.includes(queryColumn.data_type.toLowerCase())) {
|
|
338
|
+
throw new ApiError_1.default(`Query field need to be string. Unacceptable query field: ${where.field}`);
|
|
339
|
+
}
|
|
334
340
|
where.value = where.value.replace(/\*/g, "%");
|
|
335
341
|
}
|
|
336
342
|
// This means that the condition is related with another table
|
|
@@ -10,6 +10,7 @@ declare class SchemaValidatorService {
|
|
|
10
10
|
private getQueryLimitColumns;
|
|
11
11
|
private getQueryLimitKeyByFilter;
|
|
12
12
|
private getModelFillableColumns;
|
|
13
|
+
private getSearchColumns;
|
|
13
14
|
private getModelFormValidationColumns;
|
|
14
15
|
private getModelHiddenColumns;
|
|
15
16
|
private getTimestampsColumns;
|
|
@@ -73,6 +73,9 @@ class SchemaValidatorService {
|
|
|
73
73
|
...(config.PATCH || []),
|
|
74
74
|
];
|
|
75
75
|
};
|
|
76
|
+
this.getSearchColumns = (model) => {
|
|
77
|
+
return model.instance.search || [];
|
|
78
|
+
};
|
|
76
79
|
this.getModelFormValidationColumns = (model) => {
|
|
77
80
|
const validations = model.instance.validations;
|
|
78
81
|
if (!validations) {
|
|
@@ -122,6 +125,7 @@ class SchemaValidatorService {
|
|
|
122
125
|
this.version.modelList.get().forEach((model) => {
|
|
123
126
|
this.checkModelReservedKeywordsOrFail(model);
|
|
124
127
|
this.checkModelColumnsOrFail(model, this.getModelFillableColumns(model));
|
|
128
|
+
this.checkModelColumnsOrFail(model, this.getSearchColumns(model));
|
|
125
129
|
this.checkModelColumnsOrFail(model, this.getModelFormValidationColumns(model));
|
|
126
130
|
this.checkModelColumnsOrFail(model, this.getModelHiddenColumns(model));
|
|
127
131
|
this.checkModelColumnsOrFail(model, this.getTimestampsColumns(model));
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import { HandlerFunction,
|
|
2
|
-
import { IPhaseDefinition, IRouteData } from "../Interfaces";
|
|
1
|
+
import { HandlerFunction, AxeFunction, GeneralFunction } from "../Types";
|
|
2
|
+
import { IPhaseDefinition, IRouteData, IURLPair, IRouteParentPair } from "../Interfaces";
|
|
3
3
|
import AxeRequest from "./AxeRequest";
|
|
4
|
-
interface Pair {
|
|
5
|
-
method: string;
|
|
6
|
-
pattern: string;
|
|
7
|
-
data: IRouteData;
|
|
8
|
-
phases: IPhaseDefinition[];
|
|
9
|
-
hasTransaction: boolean;
|
|
10
|
-
params?: any;
|
|
11
|
-
customHandler?: HandlerFunction;
|
|
12
|
-
}
|
|
13
4
|
declare class URLService {
|
|
14
5
|
private static urls;
|
|
15
|
-
static add(method: string, pattern: string, data: IRouteData, middlewares:
|
|
16
|
-
static addHandler(method: string, pattern: string, customHandler: HandlerFunction, middlewares:
|
|
6
|
+
static add(method: string, pattern: string, data: IRouteData, middlewares: AxeFunction[], parentPairs: IRouteParentPair[]): Promise<void>;
|
|
7
|
+
static addHandler(method: string, pattern: string, customHandler: HandlerFunction, middlewares: GeneralFunction[]): Promise<void>;
|
|
17
8
|
static match(request: AxeRequest): {
|
|
18
9
|
params: any;
|
|
19
10
|
method: string;
|
|
@@ -21,9 +12,10 @@ declare class URLService {
|
|
|
21
12
|
data: IRouteData;
|
|
22
13
|
phases: IPhaseDefinition[];
|
|
23
14
|
hasTransaction: boolean;
|
|
15
|
+
parentPairs: IRouteParentPair[];
|
|
24
16
|
customHandler?: HandlerFunction | undefined;
|
|
25
17
|
} | undefined;
|
|
26
|
-
static getAllURLs():
|
|
18
|
+
static getAllURLs(): IURLPair[];
|
|
27
19
|
private static getDefaultPhases;
|
|
28
20
|
}
|
|
29
21
|
export default URLService;
|
|
@@ -36,7 +36,7 @@ const check = (url, pattern) => {
|
|
|
36
36
|
return null; // URL does not match the pattern
|
|
37
37
|
};
|
|
38
38
|
class URLService {
|
|
39
|
-
static add(method, pattern, data, middlewares) {
|
|
39
|
+
static add(method, pattern, data, middlewares, parentPairs) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
41
|
const phases = this.getDefaultPhases(middlewares);
|
|
42
42
|
if (data.handlerType && data.model) {
|
|
@@ -62,6 +62,7 @@ class URLService {
|
|
|
62
62
|
data,
|
|
63
63
|
phases,
|
|
64
64
|
hasTransaction,
|
|
65
|
+
parentPairs,
|
|
65
66
|
});
|
|
66
67
|
});
|
|
67
68
|
}
|
|
@@ -72,15 +73,15 @@ class URLService {
|
|
|
72
73
|
return {
|
|
73
74
|
isAsync: false,
|
|
74
75
|
name: `middleware:test`,
|
|
75
|
-
callback: (
|
|
76
|
+
callback: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
76
77
|
if ((0, ConverterService_1.isMiddlewareFunction)(middleware)) {
|
|
77
78
|
// It should be wrapped
|
|
78
|
-
const caller = (0, util_1.promisify)((
|
|
79
|
-
yield caller(
|
|
79
|
+
const caller = (0, util_1.promisify)((context, next) => middleware(context.req.original, context.res.original, next));
|
|
80
|
+
yield caller(context);
|
|
80
81
|
}
|
|
81
82
|
else {
|
|
82
83
|
// We call it directly.
|
|
83
|
-
yield middleware(
|
|
84
|
+
yield middleware(context.req, context.res);
|
|
84
85
|
}
|
|
85
86
|
}),
|
|
86
87
|
};
|
|
@@ -89,8 +90,8 @@ class URLService {
|
|
|
89
90
|
phases.push({
|
|
90
91
|
isAsync: false,
|
|
91
92
|
name: "customHandler",
|
|
92
|
-
callback: (
|
|
93
|
-
customHandler(
|
|
93
|
+
callback: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
customHandler(context.req, context.res);
|
|
94
95
|
}),
|
|
95
96
|
});
|
|
96
97
|
this.urls.push({
|
|
@@ -106,6 +107,7 @@ class URLService {
|
|
|
106
107
|
parentModel: null,
|
|
107
108
|
relation: null,
|
|
108
109
|
},
|
|
110
|
+
parentPairs: [],
|
|
109
111
|
});
|
|
110
112
|
});
|
|
111
113
|
}
|
|
@@ -125,7 +127,7 @@ class URLService {
|
|
|
125
127
|
return this.urls;
|
|
126
128
|
}
|
|
127
129
|
static getDefaultPhases(middlewares) {
|
|
128
|
-
// We should convert to all
|
|
130
|
+
// We should convert to all AxeFunction functions to PhaseFunctions
|
|
129
131
|
const callbacks = middlewares.map(ConverterService_1.toPhaseFunction);
|
|
130
132
|
const phases = [
|
|
131
133
|
// Internal middlewares
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HookFunctionTypes } from "src/Enums";
|
|
2
|
+
import { IModelService, IStepDefinition } from "src/Interfaces";
|
|
3
|
+
import { PhaseFunction } from "src/Types";
|
|
4
|
+
declare class Event implements IStepDefinition {
|
|
5
|
+
private hookFunctionType;
|
|
6
|
+
constructor(hookFunctionType: HookFunctionTypes);
|
|
7
|
+
get(model: IModelService): PhaseFunction;
|
|
8
|
+
get name(): string;
|
|
9
|
+
isAsync(): boolean;
|
|
10
|
+
}
|
|
11
|
+
export default Event;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Event {
|
|
4
|
+
constructor(hookFunctionType) {
|
|
5
|
+
this.hookFunctionType = hookFunctionType;
|
|
6
|
+
}
|
|
7
|
+
get(model) {
|
|
8
|
+
return model.events[this.hookFunctionType];
|
|
9
|
+
}
|
|
10
|
+
get name() {
|
|
11
|
+
return `event:${this.hookFunctionType}`;
|
|
12
|
+
}
|
|
13
|
+
isAsync() {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = Event;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HookFunctionTypes } from "src/Enums";
|
|
2
|
+
import { IModelService, IStepDefinition } from "src/Interfaces";
|
|
3
|
+
import { PhaseFunction } from "src/Types";
|
|
4
|
+
declare class Hook implements IStepDefinition {
|
|
5
|
+
private hookFunctionType;
|
|
6
|
+
constructor(hookFunctionType: HookFunctionTypes);
|
|
7
|
+
get(model: IModelService): PhaseFunction;
|
|
8
|
+
get name(): string;
|
|
9
|
+
isAsync(): boolean;
|
|
10
|
+
}
|
|
11
|
+
export default Hook;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Hook {
|
|
4
|
+
constructor(hookFunctionType) {
|
|
5
|
+
this.hookFunctionType = hookFunctionType;
|
|
6
|
+
}
|
|
7
|
+
get(model) {
|
|
8
|
+
return model.hooks[this.hookFunctionType];
|
|
9
|
+
}
|
|
10
|
+
get name() {
|
|
11
|
+
return `hook:${this.hookFunctionType}`;
|
|
12
|
+
}
|
|
13
|
+
isAsync() {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = Hook;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IStepDefinition } from "src/Interfaces";
|
|
2
|
+
import { PhaseFunction } from "src/Types";
|
|
3
|
+
declare class Phase implements IStepDefinition {
|
|
4
|
+
private callback;
|
|
5
|
+
private phaseName;
|
|
6
|
+
constructor(name: string, callback: PhaseFunction);
|
|
7
|
+
get(): PhaseFunction;
|
|
8
|
+
get name(): string;
|
|
9
|
+
isAsync(): boolean;
|
|
10
|
+
}
|
|
11
|
+
export default Phase;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Phase {
|
|
4
|
+
constructor(name, callback) {
|
|
5
|
+
this.phaseName = name;
|
|
6
|
+
this.callback = callback;
|
|
7
|
+
}
|
|
8
|
+
get() {
|
|
9
|
+
return this.callback;
|
|
10
|
+
}
|
|
11
|
+
get name() {
|
|
12
|
+
return this.phaseName;
|
|
13
|
+
}
|
|
14
|
+
isAsync() {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = Phase;
|
package/build/src/Types.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="express" />
|
|
3
3
|
import { IncomingMessage, ServerResponse } from "http";
|
|
4
|
-
import { IHandlerBaseMiddleware,
|
|
4
|
+
import { IHandlerBaseMiddleware, IContext } from "./Interfaces";
|
|
5
5
|
import AxeRequest from "./Services/AxeRequest";
|
|
6
6
|
import AxeResponse from "./Services/AxeResponse";
|
|
7
7
|
import { HookFunctionTypes } from "./Enums";
|
|
8
|
+
import { Knex } from "knex";
|
|
9
|
+
import { SchemaInspector } from "knex-schema-inspector/lib/types/schema-inspector";
|
|
8
10
|
export type ModelValidation = Record<string, string>;
|
|
9
|
-
export type
|
|
11
|
+
export type ModelHooks = Record<HookFunctionTypes, PhaseFunction>;
|
|
12
|
+
export type ModelMiddleware = Array<AxeFunction | IHandlerBaseMiddleware>;
|
|
13
|
+
export type AdaptorType = "redis" | "memory";
|
|
10
14
|
export type DefaultResponse = Promise<void> | void | undefined;
|
|
11
|
-
export type
|
|
15
|
+
export type NextFunction = (error?: any) => void;
|
|
16
|
+
export type SchemaInspectorFuction = (database: Knex) => SchemaInspector;
|
|
17
|
+
export type SerializationFunction = (item: any, request: AxeRequest) => any;
|
|
12
18
|
export type MiddlewareFunction = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => DefaultResponse;
|
|
13
19
|
export type HandlerFunction = (request: AxeRequest, response: AxeResponse) => DefaultResponse;
|
|
14
|
-
export type PhaseFunction = (
|
|
15
|
-
export type
|
|
16
|
-
export type
|
|
17
|
-
export type NextFunction = (error: any) => void;
|
|
18
|
-
export type DynamicFunctionType = (MiddlewareFunction | HandlerFunction)[];
|
|
19
|
-
export type StepTypes = MiddlewareFunction | HandlerFunction | PhaseFunction;
|
|
20
|
-
export type ModelMiddlewareDefinition = Array<StepTypes | IHandlerBaseMiddleware>;
|
|
20
|
+
export type PhaseFunction = (context: IContext) => DefaultResponse;
|
|
21
|
+
export type GeneralFunction = MiddlewareFunction | HandlerFunction;
|
|
22
|
+
export type AxeFunction = GeneralFunction | PhaseFunction;
|
package/build/src/constants.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ConditionTypes, HandlerTypes, HttpMethods, QueryFeature, Relationships } from "./Enums";
|
|
2
|
-
import {
|
|
3
|
-
import { PhaseFunction } from "./Types";
|
|
2
|
+
import { AxeConfig, AxeVersionConfig, ICacheConfiguration, IStepDefinition } from "./Interfaces";
|
|
4
3
|
export declare const RESERVED_KEYWORDS: string[];
|
|
5
4
|
export declare const DEFAULT_HANDLERS: HandlerTypes[];
|
|
6
5
|
export declare const DEFAULT_METHODS_OF_MODELS: string[];
|
|
@@ -8,6 +7,7 @@ export declare const API_ROUTE_TEMPLATES: {
|
|
|
8
7
|
store: (prefix: string, parentUrl: string, resource: string) => string;
|
|
9
8
|
paginate: (prefix: string, parentUrl: string, resource: string) => string;
|
|
10
9
|
all: (prefix: string, parentUrl: string, resource: string) => string;
|
|
10
|
+
search: (prefix: string, parentUrl: string, resource: string) => string;
|
|
11
11
|
show: (prefix: string, parentUrl: string, resource: string, primaryKey: string) => string;
|
|
12
12
|
update: (prefix: string, parentUrl: string, resource: string, primaryKey: string) => string;
|
|
13
13
|
patch: (prefix: string, parentUrl: string, resource: string, primaryKey: string) => string;
|
|
@@ -16,12 +16,11 @@ export declare const API_ROUTE_TEMPLATES: {
|
|
|
16
16
|
};
|
|
17
17
|
export declare const ConditionQueryFeatureMap: Record<ConditionTypes, QueryFeature>;
|
|
18
18
|
export declare const RelationQueryFeatureMap: Record<Relationships, QueryFeature>;
|
|
19
|
-
export declare const DEFAULT_VERSION_CONFIG: IVersionConfig;
|
|
20
19
|
export declare const NUMERIC_PRIMARY_KEY_TYPES: string[];
|
|
20
|
+
export declare const STRING_COLUMN_TYPES: string[];
|
|
21
21
|
export declare const HANDLER_METHOD_MAP: Record<HandlerTypes, HttpMethods>;
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export declare const HANDLER_CYLES: Record<HandlerTypes, ICycleDefinition[]>;
|
|
22
|
+
export declare const HANDLER_CYLES: Record<HandlerTypes, IStepDefinition[]>;
|
|
23
|
+
export declare const DEFAULT_CACHE_CONFIGURATION: ICacheConfiguration;
|
|
24
|
+
export declare const DEFAULT_APP_CONFIG: AxeConfig;
|
|
25
|
+
export declare const DEFAULT_VERSION_CONFIG: AxeVersionConfig;
|
|
26
|
+
export declare const ALL_HANDLERS: HandlerTypes[];
|