axe-api 0.30.0-rc1 → 0.30.0-rc3
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/v1/Hooks/Customer/onBeforeForceDelete.d.ts +3 -0
- package/build/dev-kit/app/{Events/UserEvent.js → v1/Hooks/Customer/onBeforeForceDelete.js} +2 -4
- package/build/dev-kit/app/v1/Hooks/Employee/onBeforeForceDelete.d.ts +2 -0
- package/build/dev-kit/app/{v2/Hooks/EmployeeHook.js → v1/Hooks/Employee/onBeforeForceDelete.js} +1 -3
- package/build/dev-kit/app/v1/Hooks/User/onBeforeInsert.d.ts +2 -0
- package/build/dev-kit/app/{v2/Events/UserEvent.js → v1/Hooks/User/onBeforeInsert.js} +2 -4
- package/build/dev-kit/app/v1/Models/Post.d.ts +2 -0
- package/build/dev-kit/app/v1/Models/Post.js +6 -0
- package/build/dev-kit/app/v1/Models/User.d.ts +1 -0
- package/build/dev-kit/app/v1/Models/User.js +9 -0
- package/build/dev-kit/app/v1/config.js +14 -11
- package/build/dev-kit/app/v1/init.js +11 -1
- package/build/dev-kit/app/v2/Models/Customer.d.ts +1 -0
- package/build/dev-kit/app/v2/Models/Customer.js +3 -0
- package/build/dev-kit/app/v2/config.js +4 -0
- package/build/dev-kit/app/v3/config.js +3 -0
- package/build/index.d.ts +3 -3
- package/build/index.js +4 -1
- package/build/src/Enums.d.ts +33 -1
- package/build/src/Enums.js +35 -1
- package/build/src/Handlers/AllHandler.js +1 -1
- package/build/src/Handlers/Helpers.d.ts +1 -0
- package/build/src/Handlers/Helpers.js +20 -3
- package/build/src/Handlers/PaginateHandler.js +1 -1
- package/build/src/Handlers/ShowHandler.js +1 -1
- package/build/src/Interfaces.d.ts +20 -3
- package/build/src/Model.d.ts +2 -1
- package/build/src/Model.js +3 -0
- package/build/src/Resolvers/FileResolver.js +4 -2
- package/build/src/Resolvers/ModelResolver.d.ts +3 -0
- package/build/src/Resolvers/ModelResolver.js +74 -12
- package/build/src/Resolvers/VersionConfigResolver.js +2 -1
- package/build/src/Server.js +2 -1
- package/build/src/Services/APIService.js +3 -0
- package/build/src/Services/LimitService.d.ts +5 -0
- package/build/src/Services/LimitService.js +116 -0
- package/build/src/Services/ModelService.d.ts +3 -1
- package/build/src/Services/ModelService.js +4 -0
- package/build/src/Services/QueryService.d.ts +3 -2
- package/build/src/Services/QueryService.js +32 -7
- package/build/src/Services/SchemaValidatorService.d.ts +4 -0
- package/build/src/Services/SchemaValidatorService.js +50 -0
- package/build/src/Services/index.d.ts +2 -1
- package/build/src/Services/index.js +4 -1
- package/build/src/Types.d.ts +1 -1
- package/build/src/constants.d.ts +5 -1
- package/build/src/constants.js +43 -1
- package/package.json +7 -5
- package/build/dev-kit/app/Config/Application.d.ts +0 -3
- package/build/dev-kit/app/Config/Application.js +0 -14
- package/build/dev-kit/app/Config/Database.d.ts +0 -3
- package/build/dev-kit/app/Config/Database.js +0 -24
- package/build/dev-kit/app/Events/UserEvent.d.ts +0 -3
- package/build/dev-kit/app/Hooks/CustomerHook.d.ts +0 -3
- package/build/dev-kit/app/Hooks/CustomerHook.js +0 -16
- package/build/dev-kit/app/Hooks/EmployeeHook.d.ts +0 -2
- package/build/dev-kit/app/Hooks/EmployeeHook.js +0 -16
- package/build/dev-kit/app/Hooks/UserHook.d.ts +0 -3
- package/build/dev-kit/app/Hooks/UserHook.js +0 -17
- package/build/dev-kit/app/Models/Customer.d.ts +0 -7
- package/build/dev-kit/app/Models/Customer.js +0 -15
- package/build/dev-kit/app/Models/Employee.d.ts +0 -9
- package/build/dev-kit/app/Models/Employee.js +0 -21
- package/build/dev-kit/app/Models/EmployeeAddress.d.ts +0 -8
- package/build/dev-kit/app/Models/EmployeeAddress.js +0 -18
- package/build/dev-kit/app/Models/Post.d.ts +0 -6
- package/build/dev-kit/app/Models/Post.js +0 -14
- package/build/dev-kit/app/Models/User.d.ts +0 -7
- package/build/dev-kit/app/Models/User.js +0 -23
- package/build/dev-kit/app/Serialization/UserSerialization.d.ts +0 -3
- package/build/dev-kit/app/Serialization/UserSerialization.js +0 -6
- package/build/dev-kit/app/init.d.ts +0 -4
- package/build/dev-kit/app/init.js +0 -16
- package/build/dev-kit/app/v1/Events/UserEvent.d.ts +0 -3
- package/build/dev-kit/app/v1/Events/UserEvent.js +0 -16
- package/build/dev-kit/app/v1/Hooks/CustomerHook.d.ts +0 -3
- package/build/dev-kit/app/v1/Hooks/CustomerHook.js +0 -16
- package/build/dev-kit/app/v1/Hooks/EmployeeHook.d.ts +0 -2
- package/build/dev-kit/app/v1/Hooks/EmployeeHook.js +0 -16
- package/build/dev-kit/app/v1/Hooks/UserHook.d.ts +0 -3
- package/build/dev-kit/app/v1/Hooks/UserHook.js +0 -17
- package/build/dev-kit/app/v2/Events/UserEvent.d.ts +0 -3
- package/build/dev-kit/app/v2/Hooks/CustomerHook.d.ts +0 -3
- package/build/dev-kit/app/v2/Hooks/CustomerHook.js +0 -16
- package/build/dev-kit/app/v2/Hooks/EmployeeHook.d.ts +0 -2
- package/build/dev-kit/app/v2/Hooks/UserHook.d.ts +0 -3
- package/build/dev-kit/app/v2/Hooks/UserHook.js +0 -17
- package/build/dev-kit/config.d.ts +0 -3
- package/build/dev-kit/config.js +0 -31
|
@@ -9,8 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
// console.log("onAfterInsert", item);
|
|
12
|
+
exports.default = ({ formData }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
throw new Error("Fake");
|
|
15
14
|
});
|
|
16
|
-
exports.onAfterInsert = onAfterInsert;
|
package/build/dev-kit/app/{v2/Hooks/EmployeeHook.js → v1/Hooks/Employee/onBeforeForceDelete.js}
RENAMED
|
@@ -9,8 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const onBeforeForceDelete = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
13
|
throw new Error("This is just a test message.");
|
|
15
14
|
});
|
|
16
|
-
exports.onBeforeForceDelete = onBeforeForceDelete;
|
|
@@ -9,8 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
// console.log("onAfterInsert", item);
|
|
12
|
+
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
// TODO
|
|
15
14
|
});
|
|
16
|
-
exports.onAfterInsert = onAfterInsert;
|
|
@@ -2,5 +2,7 @@ import { Model } from "../../../../index";
|
|
|
2
2
|
declare class Post extends Model {
|
|
3
3
|
get fillable(): string[];
|
|
4
4
|
get validations(): Record<string, string>;
|
|
5
|
+
get limits(): import("../../../../index").IQueryLimitConfig[][];
|
|
6
|
+
user(): import("../../../../index").IRelation;
|
|
5
7
|
}
|
|
6
8
|
export default Post;
|
|
@@ -2,6 +2,7 @@ import { IMethodBaseConfig, IRelation, Model } from "../../../../index";
|
|
|
2
2
|
declare class User extends Model {
|
|
3
3
|
get fillable(): IMethodBaseConfig;
|
|
4
4
|
get validations(): Record<string, string>;
|
|
5
|
+
get limits(): import("../../../../index").IQueryLimitConfig[][];
|
|
5
6
|
posts(): IRelation;
|
|
6
7
|
}
|
|
7
8
|
export default User;
|
|
@@ -16,6 +16,15 @@ class User extends index_1.Model {
|
|
|
16
16
|
surname: "required",
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
get limits() {
|
|
20
|
+
return [
|
|
21
|
+
(0, index_1.allow)(index_1.QueryFeature.WhereLike, ["name", "surname"]),
|
|
22
|
+
(0, index_1.allow)(index_1.QueryFeature.WithHasMany, ["posts"]),
|
|
23
|
+
// deny(QueryFeature.WhereGt),
|
|
24
|
+
// deny(QueryFeature.FieldsAll),
|
|
25
|
+
// deny(QueryFeature.Sorting),
|
|
26
|
+
];
|
|
27
|
+
}
|
|
19
28
|
posts() {
|
|
20
29
|
return this.hasMany("Post", "id", "user_id");
|
|
21
30
|
}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const index_1 = require("../../../index");
|
|
4
|
-
const simpleSerializer = (data
|
|
4
|
+
const simpleSerializer = (data) => {
|
|
5
5
|
data.signed = true;
|
|
6
6
|
return data;
|
|
7
7
|
};
|
|
8
|
-
const config = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const config = Object.assign(Object.assign({}, index_1.DEFAULT_VERSION_CONFIG), { transaction: [], serializers: [simpleSerializer], supportedLanguages: ["en"], defaultLanguage: "en", query: {
|
|
9
|
+
limits: [
|
|
10
|
+
(0, index_1.allow)(index_1.QueryFeature.All),
|
|
11
|
+
// allow(QueryFeature.FieldsAll),
|
|
12
|
+
// // allow(QueryFeature.WithHasOne),
|
|
13
|
+
// allow(QueryFeature.Sorting),
|
|
14
|
+
// allow(QueryFeature.WhereGt),
|
|
15
|
+
(0, index_1.deny)(index_1.QueryFeature.WithHasMany),
|
|
16
|
+
],
|
|
17
|
+
defaults: {
|
|
18
|
+
perPage: 2,
|
|
19
|
+
maxPerPage: 2,
|
|
14
20
|
},
|
|
15
|
-
|
|
16
|
-
supportedLanguages: ["en-GB", "en", "tr", "de"],
|
|
17
|
-
defaultLanguage: "en-GB",
|
|
18
|
-
};
|
|
21
|
+
} });
|
|
19
22
|
exports.default = config;
|
|
@@ -8,9 +8,19 @@ 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 });
|
|
12
15
|
exports.onAfterInit = exports.onBeforeInit = void 0;
|
|
13
|
-
const
|
|
16
|
+
const body_parser_1 = __importDefault(require("body-parser"));
|
|
17
|
+
const multer_1 = __importDefault(require("multer"));
|
|
18
|
+
const onBeforeInit = (app) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const forms = (0, multer_1.default)();
|
|
20
|
+
app.use(body_parser_1.default.urlencoded({ extended: true }));
|
|
21
|
+
app.use(forms.array("file"));
|
|
22
|
+
app.use(body_parser_1.default.json());
|
|
23
|
+
});
|
|
14
24
|
exports.onBeforeInit = onBeforeInit;
|
|
15
25
|
const onAfterInit = (app) => __awaiter(void 0, void 0, void 0, function* () { });
|
|
16
26
|
exports.onAfterInit = onAfterInit;
|
|
@@ -13,6 +13,9 @@ class Customer extends index_1.Model {
|
|
|
13
13
|
get fillable() {
|
|
14
14
|
return ["name"];
|
|
15
15
|
}
|
|
16
|
+
get limits() {
|
|
17
|
+
return [(0, index_1.allow)(index_1.QueryFeature.FieldsAll), (0, index_1.deny)(index_1.QueryFeature.Sorting, ["id"])];
|
|
18
|
+
}
|
|
16
19
|
employees() {
|
|
17
20
|
return this.hasMany("Employee", "id", "parent_id");
|
|
18
21
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("../../../index");
|
|
3
4
|
const config = {
|
|
4
5
|
transaction: [],
|
|
5
6
|
serializers: [],
|
|
6
7
|
supportedLanguages: ["en-GB", "en", "tr", "de"],
|
|
7
8
|
defaultLanguage: "en-GB",
|
|
9
|
+
query: {
|
|
10
|
+
limits: [(0, index_1.allow)(index_1.QueryFeature.Sorting)],
|
|
11
|
+
},
|
|
8
12
|
};
|
|
9
13
|
exports.default = config;
|
package/build/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Server from "./src/Server";
|
|
2
2
|
import Model from "./src/Model";
|
|
3
3
|
import ApiError from "./src/Exceptions/ApiError";
|
|
4
|
-
import { DEFAULT_HANDLERS } from "./src/constants";
|
|
5
|
-
import { IoCService } from "./src/Services";
|
|
4
|
+
import { DEFAULT_HANDLERS, DEFAULT_VERSION_CONFIG } from "./src/constants";
|
|
5
|
+
import { IoCService, allow, deny } from "./src/Services";
|
|
6
6
|
export * from "./src/Enums";
|
|
7
7
|
export * from "./src/Interfaces";
|
|
8
|
-
export { Server, Model, ApiError, DEFAULT_HANDLERS, IoCService };
|
|
8
|
+
export { Server, Model, ApiError, DEFAULT_HANDLERS, DEFAULT_VERSION_CONFIG, IoCService, allow, deny, };
|
package/build/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.IoCService = exports.DEFAULT_HANDLERS = exports.ApiError = exports.Model = exports.Server = void 0;
|
|
20
|
+
exports.deny = exports.allow = exports.IoCService = exports.DEFAULT_VERSION_CONFIG = exports.DEFAULT_HANDLERS = exports.ApiError = exports.Model = exports.Server = void 0;
|
|
21
21
|
const Server_1 = __importDefault(require("./src/Server"));
|
|
22
22
|
exports.Server = Server_1.default;
|
|
23
23
|
const Model_1 = __importDefault(require("./src/Model"));
|
|
@@ -26,7 +26,10 @@ const ApiError_1 = __importDefault(require("./src/Exceptions/ApiError"));
|
|
|
26
26
|
exports.ApiError = ApiError_1.default;
|
|
27
27
|
const constants_1 = require("./src/constants");
|
|
28
28
|
Object.defineProperty(exports, "DEFAULT_HANDLERS", { enumerable: true, get: function () { return constants_1.DEFAULT_HANDLERS; } });
|
|
29
|
+
Object.defineProperty(exports, "DEFAULT_VERSION_CONFIG", { enumerable: true, get: function () { return constants_1.DEFAULT_VERSION_CONFIG; } });
|
|
29
30
|
const Services_1 = require("./src/Services");
|
|
30
31
|
Object.defineProperty(exports, "IoCService", { enumerable: true, get: function () { return Services_1.IoCService; } });
|
|
32
|
+
Object.defineProperty(exports, "allow", { enumerable: true, get: function () { return Services_1.allow; } });
|
|
33
|
+
Object.defineProperty(exports, "deny", { enumerable: true, get: function () { return Services_1.deny; } });
|
|
31
34
|
__exportStar(require("./src/Enums"), exports);
|
|
32
35
|
__exportStar(require("./src/Interfaces"), exports);
|
package/build/src/Enums.d.ts
CHANGED
|
@@ -86,5 +86,37 @@ export declare enum AxeErrorCode {
|
|
|
86
86
|
TABLE_DOESNT_HAVE_ANY_COLUMN = "TABLE_DOESNT_HAVE_ANY_COLUMN",
|
|
87
87
|
RESERVED_VERSION_NAME = "RESERVED_VERSION_NAME",
|
|
88
88
|
UNDEFINED_COLUMN = "UNDEFINED_COLUMN",
|
|
89
|
-
UNDEFINED_RELATION_MODEL = "UNDEFINED_RELATION_MODEL"
|
|
89
|
+
UNDEFINED_RELATION_MODEL = "UNDEFINED_RELATION_MODEL",
|
|
90
|
+
UNDEFINED_HOOK_MODEL_RELATION = "UNDEFINED_HOOK_MODEL_RELATION",
|
|
91
|
+
UNACCEPTABLE_HOOK_FILE = "UNACCEPTABLE_HOOK_FILE",
|
|
92
|
+
UNDEFINED_RELATION_NAME = "UNDEFINED_RELATION_NAME"
|
|
93
|
+
}
|
|
94
|
+
export declare enum QueryFeatureType {
|
|
95
|
+
Allow = "Allow",
|
|
96
|
+
Deny = "Deny"
|
|
97
|
+
}
|
|
98
|
+
export declare enum QueryFeature {
|
|
99
|
+
All = "all",
|
|
100
|
+
FieldsAll = "fieldsAll",
|
|
101
|
+
Sorting = "sorting",
|
|
102
|
+
Limits = "limits",
|
|
103
|
+
WhereAll = "where.*",
|
|
104
|
+
WhereEqual = "where.equal",
|
|
105
|
+
WhereNotEqual = "where.notEqual",
|
|
106
|
+
WhereGt = "where.gt",
|
|
107
|
+
WhereGte = "where.gte",
|
|
108
|
+
WhereLt = "where.lt",
|
|
109
|
+
WhereLte = "where.lte",
|
|
110
|
+
WhereLike = "where.like",
|
|
111
|
+
WhereNotLike = "where.notLike",
|
|
112
|
+
WhereIn = "where.in",
|
|
113
|
+
WhereNotIn = "where.notIn",
|
|
114
|
+
WhereBetween = "where.between",
|
|
115
|
+
WhereNotBetween = "where.notBetween",
|
|
116
|
+
WhereNull = "where.null",
|
|
117
|
+
WhereNotNull = "where.notNull",
|
|
118
|
+
Trashed = "trashed",
|
|
119
|
+
WithAll = "with.*",
|
|
120
|
+
WithHasOne = "with.hasOne",
|
|
121
|
+
WithHasMany = "with.hasMany"
|
|
90
122
|
}
|
package/build/src/Enums.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AxeErrorCode = exports.TimestampColumns = exports.SortTypes = exports.Relationships = exports.LogLevels = exports.HttpMethods = exports.Extensions = exports.HookFunctionTypes = exports.HandlerTypes = exports.DependencyTypes = exports.ConditionTypes = void 0;
|
|
3
|
+
exports.QueryFeature = exports.QueryFeatureType = exports.AxeErrorCode = exports.TimestampColumns = exports.SortTypes = exports.Relationships = exports.LogLevels = exports.HttpMethods = exports.Extensions = exports.HookFunctionTypes = exports.HandlerTypes = exports.DependencyTypes = exports.ConditionTypes = void 0;
|
|
4
4
|
var ConditionTypes;
|
|
5
5
|
(function (ConditionTypes) {
|
|
6
6
|
ConditionTypes["NotNull"] = "NotNull";
|
|
@@ -101,4 +101,38 @@ var AxeErrorCode;
|
|
|
101
101
|
AxeErrorCode["RESERVED_VERSION_NAME"] = "RESERVED_VERSION_NAME";
|
|
102
102
|
AxeErrorCode["UNDEFINED_COLUMN"] = "UNDEFINED_COLUMN";
|
|
103
103
|
AxeErrorCode["UNDEFINED_RELATION_MODEL"] = "UNDEFINED_RELATION_MODEL";
|
|
104
|
+
AxeErrorCode["UNDEFINED_HOOK_MODEL_RELATION"] = "UNDEFINED_HOOK_MODEL_RELATION";
|
|
105
|
+
AxeErrorCode["UNACCEPTABLE_HOOK_FILE"] = "UNACCEPTABLE_HOOK_FILE";
|
|
106
|
+
AxeErrorCode["UNDEFINED_RELATION_NAME"] = "UNDEFINED_RELATION_NAME";
|
|
104
107
|
})(AxeErrorCode = exports.AxeErrorCode || (exports.AxeErrorCode = {}));
|
|
108
|
+
var QueryFeatureType;
|
|
109
|
+
(function (QueryFeatureType) {
|
|
110
|
+
QueryFeatureType["Allow"] = "Allow";
|
|
111
|
+
QueryFeatureType["Deny"] = "Deny";
|
|
112
|
+
})(QueryFeatureType = exports.QueryFeatureType || (exports.QueryFeatureType = {}));
|
|
113
|
+
var QueryFeature;
|
|
114
|
+
(function (QueryFeature) {
|
|
115
|
+
QueryFeature["All"] = "all";
|
|
116
|
+
QueryFeature["FieldsAll"] = "fieldsAll";
|
|
117
|
+
QueryFeature["Sorting"] = "sorting";
|
|
118
|
+
QueryFeature["Limits"] = "limits";
|
|
119
|
+
QueryFeature["WhereAll"] = "where.*";
|
|
120
|
+
QueryFeature["WhereEqual"] = "where.equal";
|
|
121
|
+
QueryFeature["WhereNotEqual"] = "where.notEqual";
|
|
122
|
+
QueryFeature["WhereGt"] = "where.gt";
|
|
123
|
+
QueryFeature["WhereGte"] = "where.gte";
|
|
124
|
+
QueryFeature["WhereLt"] = "where.lt";
|
|
125
|
+
QueryFeature["WhereLte"] = "where.lte";
|
|
126
|
+
QueryFeature["WhereLike"] = "where.like";
|
|
127
|
+
QueryFeature["WhereNotLike"] = "where.notLike";
|
|
128
|
+
QueryFeature["WhereIn"] = "where.in";
|
|
129
|
+
QueryFeature["WhereNotIn"] = "where.notIn";
|
|
130
|
+
QueryFeature["WhereBetween"] = "where.between";
|
|
131
|
+
QueryFeature["WhereNotBetween"] = "where.notBetween";
|
|
132
|
+
QueryFeature["WhereNull"] = "where.null";
|
|
133
|
+
QueryFeature["WhereNotNull"] = "where.notNull";
|
|
134
|
+
QueryFeature["Trashed"] = "trashed";
|
|
135
|
+
QueryFeature["WithAll"] = "with.*";
|
|
136
|
+
QueryFeature["WithHasOne"] = "with.hasOne";
|
|
137
|
+
QueryFeature["WithHasMany"] = "with.hasMany";
|
|
138
|
+
})(QueryFeature = exports.QueryFeature || (exports.QueryFeature = {}));
|
|
@@ -14,7 +14,7 @@ const Services_1 = require("../Services");
|
|
|
14
14
|
const Enums_1 = require("../Enums");
|
|
15
15
|
exports.default = (pack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
const { version, model, req, res, database, relation, parentModel } = pack;
|
|
17
|
-
const queryParser = new Services_1.QueryService(model, version.modelList.get());
|
|
17
|
+
const queryParser = new Services_1.QueryService(model, version.modelList.get(), version.config);
|
|
18
18
|
// We should parse URL query string to use as condition in Lucid query
|
|
19
19
|
const conditions = queryParser.get(req.query);
|
|
20
20
|
// Creating a new database query
|
|
@@ -14,3 +14,4 @@ export declare const serializeData: (version: IVersion, itemArray: any[] | any,
|
|
|
14
14
|
export declare const filterHiddenFields: (itemArray: any[], hiddens: string[] | null) => void;
|
|
15
15
|
export declare const addSoftDeleteQuery: (model: IModelService, conditions: IQuery | null, query: Knex.QueryBuilder) => void;
|
|
16
16
|
export declare const getRelatedData: (version: IVersion, data: any[], withArray: IWith[], model: IModelService, modelList: ModelListService, database: Knex | Knex.Transaction, handler: HandlerTypes, request: Request) => Promise<void>;
|
|
17
|
+
export declare const isBoolean: (value: any) => boolean;
|
|
@@ -12,11 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getRelatedData = exports.addSoftDeleteQuery = exports.filterHiddenFields = exports.serializeData = exports.addForeignKeyQuery = exports.getParentColumn = exports.callHooks = exports.getMergedFormData = exports.bindTimestampValues = void 0;
|
|
15
|
+
exports.isBoolean = exports.getRelatedData = exports.addSoftDeleteQuery = exports.filterHiddenFields = exports.serializeData = exports.addForeignKeyQuery = exports.getParentColumn = exports.callHooks = exports.getMergedFormData = exports.bindTimestampValues = void 0;
|
|
16
16
|
const change_case_1 = require("change-case");
|
|
17
17
|
const Enums_1 = require("../Enums");
|
|
18
18
|
const ApiError_1 = __importDefault(require("../Exceptions/ApiError"));
|
|
19
19
|
const Services_1 = require("../Services");
|
|
20
|
+
const LimitService_1 = require("../Services/LimitService");
|
|
21
|
+
const constants_1 = require("../constants");
|
|
20
22
|
const bindTimestampValues = (formData, columnTypes = [], model) => {
|
|
21
23
|
if (columnTypes.includes(Enums_1.TimestampColumns.CREATED_AT) &&
|
|
22
24
|
model.instance.createdAtColumn) {
|
|
@@ -138,8 +140,10 @@ const filterHiddenFields = (itemArray, hiddens) => {
|
|
|
138
140
|
};
|
|
139
141
|
exports.filterHiddenFields = filterHiddenFields;
|
|
140
142
|
const addSoftDeleteQuery = (model, conditions, query) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
if (conditions !== null && (conditions === null || conditions === void 0 ? void 0 : conditions.trashed) === true) {
|
|
144
|
+
(0, LimitService_1.valideteQueryFeature)(model, Enums_1.QueryFeature.Trashed);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
143
147
|
if (model.instance.deletedAtColumn) {
|
|
144
148
|
query.whereNull(model.instance.deletedAtColumn);
|
|
145
149
|
}
|
|
@@ -162,6 +166,8 @@ const getRelatedData = (version, data, withArray, model, modelList, database, ha
|
|
|
162
166
|
if (!foreignModel) {
|
|
163
167
|
continue;
|
|
164
168
|
}
|
|
169
|
+
// Validating the query limit
|
|
170
|
+
(0, LimitService_1.valideteQueryFeature)(model, constants_1.RelationQueryFeatureMap[definedRelation.type], `${model.instance.table}.${definedRelation.name}`, `${model.instance.table}.${definedRelation.name}`);
|
|
165
171
|
let dataField = "primaryKey";
|
|
166
172
|
let searchField = "foreignKey";
|
|
167
173
|
if (definedRelation.type !== Enums_1.Relationships.HAS_MANY) {
|
|
@@ -225,3 +231,14 @@ const getRelatedData = (version, data, withArray, model, modelList, database, ha
|
|
|
225
231
|
}
|
|
226
232
|
});
|
|
227
233
|
exports.getRelatedData = getRelatedData;
|
|
234
|
+
const isBoolean = (value) => {
|
|
235
|
+
if (value === undefined || value === null) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
value = (value || "").trim().toLocaleLowerCase();
|
|
239
|
+
if (value === "true" || value === "1" || value === "on" || value === "yes") {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
};
|
|
244
|
+
exports.isBoolean = isBoolean;
|
|
@@ -14,7 +14,7 @@ const Enums_1 = require("../Enums");
|
|
|
14
14
|
const Services_1 = require("../Services");
|
|
15
15
|
exports.default = (pack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
const { version, model, req, database, relation, parentModel } = pack;
|
|
17
|
-
const queryParser = new Services_1.QueryService(model, version.modelList.get());
|
|
17
|
+
const queryParser = new Services_1.QueryService(model, version.modelList.get(), version.config);
|
|
18
18
|
// We should parse URL query string to use as condition in Lucid query
|
|
19
19
|
const conditions = queryParser.get(req.query);
|
|
20
20
|
// Creating a new database query
|
|
@@ -18,7 +18,7 @@ const ApiError_1 = __importDefault(require("../Exceptions/ApiError"));
|
|
|
18
18
|
const Services_1 = require("../Services");
|
|
19
19
|
exports.default = (pack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
20
|
const { version, model, req, res, database, relation, parentModel } = pack;
|
|
21
|
-
const queryParser = new Services_1.QueryService(model, version.modelList.get());
|
|
21
|
+
const queryParser = new Services_1.QueryService(model, version.modelList.get(), version.config);
|
|
22
22
|
// We should parse URL query string to use as condition in Lucid query
|
|
23
23
|
const conditions = queryParser.get(req.query);
|
|
24
24
|
// Fetching item
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Knex } from "knex";
|
|
2
2
|
import { Express, Request, Response, NextFunction } from "express";
|
|
3
3
|
import { Column } from "knex-schema-inspector/lib/types/column";
|
|
4
|
-
import { HandlerTypes, LogLevels, HttpMethods, HookFunctionTypes, Extensions, Relationships, SortTypes, ConditionTypes, DependencyTypes } from "./Enums";
|
|
4
|
+
import { HandlerTypes, LogLevels, HttpMethods, HookFunctionTypes, Extensions, Relationships, SortTypes, ConditionTypes, DependencyTypes, QueryFeature, QueryFeatureType } from "./Enums";
|
|
5
5
|
import Model from "./Model";
|
|
6
6
|
import { SerializationFunction } from "./Types";
|
|
7
7
|
import { ModelListService } from "./Services";
|
|
@@ -18,11 +18,26 @@ interface IHandlerBasedSerializer {
|
|
|
18
18
|
handler: HandlerTypes[];
|
|
19
19
|
serializer: ((data: any, request: Request) => void)[];
|
|
20
20
|
}
|
|
21
|
+
export interface IQueryLimitConfig {
|
|
22
|
+
feature: QueryFeature;
|
|
23
|
+
type: QueryFeatureType;
|
|
24
|
+
key: string | null;
|
|
25
|
+
}
|
|
26
|
+
export interface IQueryDefaultConfig {
|
|
27
|
+
perPage?: number;
|
|
28
|
+
minPerPage?: number;
|
|
29
|
+
maxPerPage?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface IQueryConfig {
|
|
32
|
+
limits: Array<IQueryLimitConfig[]>;
|
|
33
|
+
defaults?: IQueryDefaultConfig;
|
|
34
|
+
}
|
|
21
35
|
export interface IVersionConfig {
|
|
22
36
|
transaction: boolean | IHandlerBasedTransactionConfig | IHandlerBasedTransactionConfig[];
|
|
23
37
|
serializers: ((data: any, request: Request) => void)[] | IHandlerBasedSerializer[];
|
|
24
38
|
supportedLanguages: string[];
|
|
25
39
|
defaultLanguage: string;
|
|
40
|
+
query: IQueryConfig;
|
|
26
41
|
}
|
|
27
42
|
export interface IApplicationConfig extends IConfig {
|
|
28
43
|
env: string;
|
|
@@ -40,7 +55,7 @@ export interface IAcceptedLanguage {
|
|
|
40
55
|
language: ILanguage;
|
|
41
56
|
quality: number;
|
|
42
57
|
}
|
|
43
|
-
export
|
|
58
|
+
export type IDatabaseConfig = Knex.Config;
|
|
44
59
|
export interface IVersionFolder {
|
|
45
60
|
root: string;
|
|
46
61
|
config: string;
|
|
@@ -104,9 +119,11 @@ export interface IModelService {
|
|
|
104
119
|
events: Record<HookFunctionTypes, (params: IHookParameter) => void>;
|
|
105
120
|
isRecursive: boolean;
|
|
106
121
|
children: IModelService[];
|
|
122
|
+
queryLimits: IQueryLimitConfig[];
|
|
107
123
|
serialize: SerializationFunction | null;
|
|
108
124
|
setColumns(columns: IColumn[]): void;
|
|
109
125
|
setExtensions(type: Extensions, hookFunctionType: HookFunctionTypes, data: (params: IHookParameter) => void): void;
|
|
126
|
+
setQueryLimits(limits: IQueryLimitConfig[]): void;
|
|
110
127
|
setSerialization(callback: SerializationFunction): void;
|
|
111
128
|
}
|
|
112
129
|
export interface IRelation {
|
|
@@ -173,7 +190,7 @@ export interface IWhere {
|
|
|
173
190
|
value: any;
|
|
174
191
|
relation: IRelation | null;
|
|
175
192
|
}
|
|
176
|
-
export
|
|
193
|
+
export type NestedWhere = Array<NestedWhere | IWhere>;
|
|
177
194
|
export interface IDependency {
|
|
178
195
|
type: DependencyTypes;
|
|
179
196
|
callback: any;
|
package/build/src/Model.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
import { IRelation, IMethodBaseConfig, IMethodBaseValidations, IHandlerBaseMiddleware, IHandlerBasedTransactionConfig } from "./Interfaces";
|
|
2
|
+
import { IRelation, IMethodBaseConfig, IMethodBaseValidations, IHandlerBaseMiddleware, IHandlerBasedTransactionConfig, IQueryLimitConfig } from "./Interfaces";
|
|
3
3
|
import { HandlerTypes, HttpMethods } from "./Enums";
|
|
4
4
|
declare class Model {
|
|
5
5
|
get primaryKey(): string;
|
|
@@ -14,6 +14,7 @@ declare class Model {
|
|
|
14
14
|
get deletedAtColumn(): string | null;
|
|
15
15
|
get transaction(): boolean | IHandlerBasedTransactionConfig | IHandlerBasedTransactionConfig[] | null;
|
|
16
16
|
get ignore(): boolean;
|
|
17
|
+
get limits(): Array<IQueryLimitConfig[]>;
|
|
17
18
|
getFillableFields(methodType: HttpMethods): string[];
|
|
18
19
|
getValidationRules(methodType: HttpMethods): Record<string, string> | null;
|
|
19
20
|
getMiddlewares(handlerType: HandlerTypes): ((req: Request, res: Response, next: NextFunction) => void)[];
|
package/build/src/Model.js
CHANGED
|
@@ -40,6 +40,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
40
40
|
class FileResolver {
|
|
41
41
|
resolve(directory) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
var _a;
|
|
43
44
|
const results = {};
|
|
44
45
|
if (!fs_1.default.existsSync(directory)) {
|
|
45
46
|
return results;
|
|
@@ -50,7 +51,7 @@ class FileResolver {
|
|
|
50
51
|
.map((item) => item.name);
|
|
51
52
|
for (const file of files) {
|
|
52
53
|
const configFile = path_1.default.join(directory, file);
|
|
53
|
-
const { default: content } = yield Promise.resolve().then(() => __importStar(require(
|
|
54
|
+
const { default: content } = yield (_a = configFile, Promise.resolve().then(() => __importStar(require(_a))));
|
|
54
55
|
const key = file.replace(".ts", "").replace(".js", "");
|
|
55
56
|
if (content === null || content === void 0 ? void 0 : content.prototype) {
|
|
56
57
|
results[key] = new content();
|
|
@@ -64,6 +65,7 @@ class FileResolver {
|
|
|
64
65
|
}
|
|
65
66
|
resolveContent(directory) {
|
|
66
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
var _a;
|
|
67
69
|
const results = {};
|
|
68
70
|
if (!fs_1.default.existsSync(directory)) {
|
|
69
71
|
return results;
|
|
@@ -74,7 +76,7 @@ class FileResolver {
|
|
|
74
76
|
.map((item) => item.name);
|
|
75
77
|
for (const file of files) {
|
|
76
78
|
const configFile = path_1.default.join(directory, file);
|
|
77
|
-
const content = yield Promise.resolve().then(() => __importStar(require(
|
|
79
|
+
const content = yield (_a = configFile, Promise.resolve().then(() => __importStar(require(_a))));
|
|
78
80
|
const key = file.replace(".ts", "").replace(".js", "");
|
|
79
81
|
results[key] = content;
|
|
80
82
|
}
|
|
@@ -7,7 +7,10 @@ declare class ModelResolver {
|
|
|
7
7
|
private getModelList;
|
|
8
8
|
private setDatabaseColumns;
|
|
9
9
|
private setModelHooks;
|
|
10
|
+
private getDirectories;
|
|
11
|
+
private checkOldStyleHookFiles;
|
|
10
12
|
private setModelSerializations;
|
|
13
|
+
private setModelQueryLimits;
|
|
11
14
|
private getInstanceMethods;
|
|
12
15
|
}
|
|
13
16
|
export default ModelResolver;
|