axe-api 0.30.2 → 0.31.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/CHANGELOG.md +17 -1
- package/build/src/Builders/RouterBuilder.js +11 -9
- package/build/src/Handlers/DestroyHandler.js +5 -1
- package/build/src/Handlers/DocsHTMLHandler.js +24 -0
- package/build/src/Handlers/ForceDestroyHandler.js +5 -1
- package/build/src/Handlers/Helpers.d.ts +1 -0
- package/build/src/Handlers/Helpers.js +9 -1
- package/build/src/Handlers/MetadataHandler.d.ts +3 -0
- package/build/src/Handlers/PatchHandler.js +5 -3
- package/build/src/Handlers/ShowHandler.js +5 -2
- package/build/src/Handlers/UpdateHandler.js +5 -3
- package/build/src/Interfaces.d.ts +6 -0
- package/build/src/Server.js +4 -2
- package/build/src/Services/DocumentationService.d.ts +3 -3
- package/build/src/Services/DocumentationService.js +8 -1
- package/package.json +1 -1
- /package/build/src/Handlers/{DocsHandler.d.ts → DocsHTMLHandler.d.ts} +0 -0
- /package/build/src/Handlers/{DocsHandler.js → MetadataHandler.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## [0.31.0 (2023-05-05)](https://github.com/axe-api/axe-api/compare/0.31.0...0.30.3)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Added new auto-created documentation values [#179](https://github.com/axe-api/axe-api/issues/179)
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Fixed PostgreSQL-related issues [#204](https://github.com/axe-api/axe-api/issues/204)
|
|
12
|
+
|
|
13
|
+
## [0.30.3 (2023-05-05)](https://github.com/axe-api/axe-api/compare/0.30.3...0.30.2)
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Fixed security issues on dependencies.
|
|
18
|
+
|
|
3
19
|
## [0.30.2 (2023-04-18)](https://github.com/axe-api/axe-api/compare/0.30.2...0.30.1)
|
|
4
20
|
|
|
5
21
|
### Features
|
|
@@ -10,7 +26,7 @@
|
|
|
10
26
|
|
|
11
27
|
### Fixed
|
|
12
28
|
|
|
13
|
-
- Fixed URL slash character difference between windows and
|
|
29
|
+
- Fixed URL slash character difference between windows and \*nix [#164](https://github.com/axe-api/axe-api/issues/164)
|
|
14
30
|
|
|
15
31
|
## [0.30.0 (2023-04-05)](https://github.com/axe-api/axe-api/compare/0.30.0...0.22.0)
|
|
16
32
|
|
|
@@ -126,40 +126,42 @@ class RouterBuilder {
|
|
|
126
126
|
const docs = Services_1.DocumentationService.getInstance();
|
|
127
127
|
const app = yield Services_1.IoCService.useByType("App");
|
|
128
128
|
const handler = (req, res) => {
|
|
129
|
-
this.requestHandler(handlerType, req, res, model, parentModel, relation)
|
|
129
|
+
this.requestHandler(handlerType, req, res, model, parentModel, relation).catch((error) => {
|
|
130
|
+
this.sendErrorAsResponse(res, error);
|
|
131
|
+
});
|
|
130
132
|
};
|
|
131
133
|
switch (handlerType) {
|
|
132
134
|
case Enums_1.HandlerTypes.ALL:
|
|
133
135
|
app.get(url, middlewares, handler);
|
|
134
|
-
docs.push(Enums_1.HttpMethods.GET, url, model);
|
|
136
|
+
docs.push(this.version, Enums_1.HandlerTypes.ALL, Enums_1.HttpMethods.GET, url, model);
|
|
135
137
|
break;
|
|
136
138
|
case Enums_1.HandlerTypes.DELETE:
|
|
137
139
|
app.delete(url, middlewares, handler);
|
|
138
|
-
docs.push(Enums_1.HttpMethods.DELETE, url, model);
|
|
140
|
+
docs.push(this.version, Enums_1.HandlerTypes.DELETE, Enums_1.HttpMethods.DELETE, url, model);
|
|
139
141
|
break;
|
|
140
142
|
case Enums_1.HandlerTypes.FORCE_DELETE:
|
|
141
143
|
app.delete(url, middlewares, handler);
|
|
142
|
-
docs.push(Enums_1.HttpMethods.DELETE, url, model);
|
|
144
|
+
docs.push(this.version, Enums_1.HandlerTypes.FORCE_DELETE, Enums_1.HttpMethods.DELETE, url, model);
|
|
143
145
|
break;
|
|
144
146
|
case Enums_1.HandlerTypes.INSERT:
|
|
145
147
|
app.post(url, middlewares, handler);
|
|
146
|
-
docs.push(Enums_1.HttpMethods.POST, url, model);
|
|
148
|
+
docs.push(this.version, Enums_1.HandlerTypes.INSERT, Enums_1.HttpMethods.POST, url, model);
|
|
147
149
|
break;
|
|
148
150
|
case Enums_1.HandlerTypes.PAGINATE:
|
|
149
151
|
app.get(url, middlewares, handler);
|
|
150
|
-
docs.push(Enums_1.HttpMethods.GET, url, model);
|
|
152
|
+
docs.push(this.version, Enums_1.HandlerTypes.PAGINATE, Enums_1.HttpMethods.GET, url, model);
|
|
151
153
|
break;
|
|
152
154
|
case Enums_1.HandlerTypes.PATCH:
|
|
153
155
|
app.patch(url, middlewares, handler);
|
|
154
|
-
docs.push(Enums_1.HttpMethods.PATCH, url, model);
|
|
156
|
+
docs.push(this.version, Enums_1.HandlerTypes.PATCH, Enums_1.HttpMethods.PATCH, url, model);
|
|
155
157
|
break;
|
|
156
158
|
case Enums_1.HandlerTypes.SHOW:
|
|
157
159
|
app.get(url, middlewares, handler);
|
|
158
|
-
docs.push(Enums_1.HttpMethods.GET, url, model);
|
|
160
|
+
docs.push(this.version, Enums_1.HandlerTypes.SHOW, Enums_1.HttpMethods.GET, url, model);
|
|
159
161
|
break;
|
|
160
162
|
case Enums_1.HandlerTypes.UPDATE:
|
|
161
163
|
app.put(url, middlewares, handler);
|
|
162
|
-
docs.push(Enums_1.HttpMethods.PUT, url, model);
|
|
164
|
+
docs.push(this.version, Enums_1.HandlerTypes.UPDATE, Enums_1.HttpMethods.PUT, url, model);
|
|
163
165
|
break;
|
|
164
166
|
default:
|
|
165
167
|
throw new Error("Undefined handler type");
|
|
@@ -17,9 +17,13 @@ const Enums_1 = require("../Enums");
|
|
|
17
17
|
const ApiError_1 = __importDefault(require("../Exceptions/ApiError"));
|
|
18
18
|
exports.default = (pack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
const { model, req, res, database, relation, parentModel } = pack;
|
|
20
|
+
// We should check the parameter type
|
|
21
|
+
const value = req.params[model.instance.primaryKey];
|
|
22
|
+
(0, Helpers_1.checkPrimaryKeyValueType)(model, value);
|
|
23
|
+
// Adding the main query
|
|
20
24
|
const query = database
|
|
21
25
|
.from(model.instance.table)
|
|
22
|
-
.where(model.instance.primaryKey,
|
|
26
|
+
.where(model.instance.primaryKey, value);
|
|
23
27
|
// If there is a deletedAtColumn, it means that this table support soft-delete
|
|
24
28
|
(0, Helpers_1.addSoftDeleteQuery)(model, null, query);
|
|
25
29
|
// If there is a relation, we should bind it
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const CLOUD_FRONT_DOMAIN = "https://dw7lgbuj348m4.cloudfront.net/v1";
|
|
13
|
+
exports.default = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
try {
|
|
15
|
+
const result = yield fetch(`${CLOUD_FRONT_DOMAIN}/index.html`);
|
|
16
|
+
const content = (yield result.text())
|
|
17
|
+
.replaceAll(`src="`, `src="${CLOUD_FRONT_DOMAIN}`)
|
|
18
|
+
.replaceAll(`href="`, `href="${CLOUD_FRONT_DOMAIN}`);
|
|
19
|
+
res.send(content);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
res.send("404");
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -17,9 +17,13 @@ const Enums_1 = require("../Enums");
|
|
|
17
17
|
const ApiError_1 = __importDefault(require("../Exceptions/ApiError"));
|
|
18
18
|
exports.default = (pack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
const { model, req, res, database, relation, parentModel } = pack;
|
|
20
|
+
// We should check the parameter type
|
|
21
|
+
const value = req.params[model.instance.primaryKey];
|
|
22
|
+
(0, Helpers_1.checkPrimaryKeyValueType)(model, value);
|
|
23
|
+
// Adding the main query
|
|
20
24
|
const query = database
|
|
21
25
|
.from(model.instance.table)
|
|
22
|
-
.where(model.instance.primaryKey,
|
|
26
|
+
.where(model.instance.primaryKey, value);
|
|
23
27
|
// If there is a deletedAtColumn, it means that this table support soft-delete
|
|
24
28
|
if (model.instance.deletedAtColumn === null) {
|
|
25
29
|
throw new ApiError_1.default("You can use force delete only soft-delete supported models.");
|
|
@@ -9,6 +9,7 @@ export declare const bindTimestampValues: (formData: Record<string, any>, column
|
|
|
9
9
|
export declare const getMergedFormData: (req: Request, fillables: string[]) => Record<string, any>;
|
|
10
10
|
export declare const callHooks: (model: IModelService, type: HookFunctionTypes, params: IHookParameter) => Promise<void>;
|
|
11
11
|
export declare const getParentColumn: (relation: IRelation | null) => string | null;
|
|
12
|
+
export declare const checkPrimaryKeyValueType: (model: IModelService, value: any) => void;
|
|
12
13
|
export declare const addForeignKeyQuery: (request: Request, query: Knex.QueryBuilder, relation: IRelation | null, parentModel: IModelService | null) => void;
|
|
13
14
|
export declare const serializeData: (version: IVersion, itemArray: any[] | any, modelSerializer: SerializationFunction | null, handler: HandlerTypes, request: Request) => Promise<any[]>;
|
|
14
15
|
export declare const filterHiddenFields: (itemArray: any[], hiddens: string[] | null) => void;
|
|
@@ -12,7 +12,7 @@ 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.isBoolean = 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.checkPrimaryKeyValueType = 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"));
|
|
@@ -63,6 +63,14 @@ const getParentColumn = (relation) => {
|
|
|
63
63
|
return (0, change_case_1.camelCase)(relation.foreignKey);
|
|
64
64
|
};
|
|
65
65
|
exports.getParentColumn = getParentColumn;
|
|
66
|
+
const checkPrimaryKeyValueType = (model, value) => {
|
|
67
|
+
// We should check the parameter type
|
|
68
|
+
const primaryColumn = model.columns.find((column) => column.name === model.instance.primaryKey);
|
|
69
|
+
if ((primaryColumn === null || primaryColumn === void 0 ? void 0 : primaryColumn.data_type) === "integer" && isNaN(parseInt(value))) {
|
|
70
|
+
throw new ApiError_1.default(`Unacceptable parameter: ${value}`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
exports.checkPrimaryKeyValueType = checkPrimaryKeyValueType;
|
|
66
74
|
const addForeignKeyQuery = (request, query, relation, parentModel) => {
|
|
67
75
|
if (relation && parentModel) {
|
|
68
76
|
const parentColumn = (0, exports.getParentColumn)(relation);
|
|
@@ -24,9 +24,11 @@ exports.default = (pack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
24
24
|
// If there is a deletedAtColumn, it means that this table support soft-delete
|
|
25
25
|
(0, Helpers_1.addSoftDeleteQuery)(model, null, query);
|
|
26
26
|
yield (0, Helpers_1.callHooks)(model, Enums_1.HookFunctionTypes.onBeforeUpdateQuery, Object.assign(Object.assign({}, pack), { query }));
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
// We should check the parameter type
|
|
28
|
+
const value = req.params[model.instance.primaryKey];
|
|
29
|
+
(0, Helpers_1.checkPrimaryKeyValueType)(model, value);
|
|
30
|
+
// Adding the main query
|
|
31
|
+
let item = yield query.where(model.instance.primaryKey, value).first();
|
|
30
32
|
if (!item) {
|
|
31
33
|
throw new ApiError_1.default(`The item is not found on ${model.name}.`);
|
|
32
34
|
}
|
|
@@ -29,8 +29,11 @@ exports.default = (pack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
29
29
|
queryParser.applyFields(query, conditions.fields);
|
|
30
30
|
// If there is a relation, we should bind it
|
|
31
31
|
(0, Helpers_1.addForeignKeyQuery)(req, query, relation, parentModel);
|
|
32
|
-
// We should
|
|
33
|
-
|
|
32
|
+
// We should check the parameter type
|
|
33
|
+
const value = req.params[model.instance.primaryKey];
|
|
34
|
+
(0, Helpers_1.checkPrimaryKeyValueType)(model, value);
|
|
35
|
+
// Adding the main query
|
|
36
|
+
query.where(model.instance.primaryKey, value);
|
|
34
37
|
yield (0, Helpers_1.callHooks)(model, Enums_1.HookFunctionTypes.onBeforeShow, Object.assign(Object.assign({}, pack), { query,
|
|
35
38
|
conditions }));
|
|
36
39
|
// Users should be able to filter records
|
|
@@ -24,9 +24,11 @@ exports.default = (pack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
24
24
|
// If there is a deletedAtColumn, it means that this table support soft-delete
|
|
25
25
|
(0, Helpers_1.addSoftDeleteQuery)(model, null, query);
|
|
26
26
|
yield (0, Helpers_1.callHooks)(model, Enums_1.HookFunctionTypes.onBeforeUpdateQuery, Object.assign(Object.assign({}, pack), { query }));
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
// We should check the parameter type
|
|
28
|
+
const value = req.params[model.instance.primaryKey];
|
|
29
|
+
(0, Helpers_1.checkPrimaryKeyValueType)(model, value);
|
|
30
|
+
// Adding the main query
|
|
31
|
+
let item = yield query.where(model.instance.primaryKey, value).first();
|
|
30
32
|
if (!item) {
|
|
31
33
|
throw new ApiError_1.default(`The item is not found on ${model.name}.`);
|
|
32
34
|
}
|
|
@@ -145,13 +145,19 @@ export interface IRequestPack {
|
|
|
145
145
|
database: Knex | Knex.Transaction;
|
|
146
146
|
}
|
|
147
147
|
export interface IRouteDocumentation {
|
|
148
|
+
version: string;
|
|
149
|
+
handler: string;
|
|
148
150
|
model: string;
|
|
149
151
|
table: string;
|
|
150
152
|
columns: IColumn[];
|
|
153
|
+
hiddens: string[];
|
|
154
|
+
relations: IRelation[];
|
|
151
155
|
method: HttpMethods;
|
|
152
156
|
url: string;
|
|
153
157
|
fillables: string[];
|
|
154
158
|
validations: Record<string, string> | null;
|
|
159
|
+
queryLimits: IQueryLimitConfig[];
|
|
160
|
+
queryDefaults: IQueryDefaultConfig;
|
|
155
161
|
}
|
|
156
162
|
export interface IRawQuery {
|
|
157
163
|
q: string | null;
|
package/build/src/Server.js
CHANGED
|
@@ -44,7 +44,8 @@ const knex_schema_inspector_1 = __importDefault(require("knex-schema-inspector")
|
|
|
44
44
|
const knex_paginate_1 = require("knex-paginate");
|
|
45
45
|
const Builders_1 = require("./Builders");
|
|
46
46
|
const Services_1 = require("./Services");
|
|
47
|
-
const
|
|
47
|
+
const MetadataHandler_1 = __importDefault(require("./Handlers/MetadataHandler"));
|
|
48
|
+
const DocsHTMLHandler_1 = __importDefault(require("./Handlers/DocsHTMLHandler"));
|
|
48
49
|
const RoutesHandler_1 = __importDefault(require("./Handlers/RoutesHandler"));
|
|
49
50
|
const Helpers_1 = require("./Helpers");
|
|
50
51
|
class Server {
|
|
@@ -118,7 +119,8 @@ class Server {
|
|
|
118
119
|
const logger = Services_1.LogService.getInstance();
|
|
119
120
|
const api = Services_1.APIService.getInstance();
|
|
120
121
|
if (api.config.env === "development") {
|
|
121
|
-
app.get("/
|
|
122
|
+
app.get("/metadata", MetadataHandler_1.default);
|
|
123
|
+
app.get("/docs", DocsHTMLHandler_1.default);
|
|
122
124
|
app.get("/routes", RoutesHandler_1.default);
|
|
123
125
|
}
|
|
124
126
|
app.listen(api.config.port, () => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { IModelService, IRouteDocumentation } from "../Interfaces";
|
|
2
|
-
import { HttpMethods } from "../Enums";
|
|
1
|
+
import { IModelService, IRouteDocumentation, IVersion } from "../Interfaces";
|
|
2
|
+
import { HandlerTypes, HttpMethods } from "../Enums";
|
|
3
3
|
declare class DocumentationService {
|
|
4
4
|
private static instance;
|
|
5
5
|
private routes;
|
|
6
6
|
constructor();
|
|
7
7
|
static getInstance(): DocumentationService;
|
|
8
|
-
push(method: HttpMethods, url: string, model: IModelService): void;
|
|
8
|
+
push(version: IVersion, handler: HandlerTypes, method: HttpMethods, url: string, model: IModelService): void;
|
|
9
9
|
get(): IRouteDocumentation[];
|
|
10
10
|
}
|
|
11
11
|
export default DocumentationService;
|
|
@@ -10,15 +10,22 @@ class DocumentationService {
|
|
|
10
10
|
}
|
|
11
11
|
return DocumentationService.instance;
|
|
12
12
|
}
|
|
13
|
-
push(method, url, model) {
|
|
13
|
+
push(version, handler, method, url, model) {
|
|
14
|
+
var _a, _b;
|
|
14
15
|
this.routes.push({
|
|
16
|
+
version: version.name,
|
|
17
|
+
handler,
|
|
15
18
|
model: model.name,
|
|
16
19
|
table: model.instance.table,
|
|
17
20
|
columns: model.columns,
|
|
21
|
+
hiddens: model.instance.hiddens,
|
|
22
|
+
relations: model.relations,
|
|
18
23
|
method,
|
|
19
24
|
url,
|
|
20
25
|
fillables: model.instance.getFillableFields(method),
|
|
21
26
|
validations: model.instance.getValidationRules(method),
|
|
27
|
+
queryLimits: model.queryLimits,
|
|
28
|
+
queryDefaults: ((_b = (_a = version.config) === null || _a === void 0 ? void 0 : _a.query) === null || _b === void 0 ? void 0 : _b.defaults) || {},
|
|
22
29
|
});
|
|
23
30
|
}
|
|
24
31
|
get() {
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|