axe-api 0.19.2 → 0.20.0-rc1
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/package.json +62 -56
- package/readme.md +145 -145
- package/.eslintrc.cjs +0 -24
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -32
- package/.github/workflows/auto-tag.yml +0 -15
- package/.github/workflows/npm-publish.yml +0 -18
- package/.github/workflows/test-integration.yml +0 -29
- package/.github/workflows/test-unit.yml +0 -23
- package/CHANGELOG.md +0 -150
- package/babel.config.cjs +0 -12
- package/index.js +0 -21
- package/jest.config.js +0 -4
- package/src/Server.js +0 -118
- package/src/constants.js +0 -148
- package/src/core/Config.js +0 -38
- package/src/core/Docs.js +0 -43
- package/src/core/HttpResponse.js +0 -10
- package/src/core/IoC.js +0 -41
- package/src/core/Logger.js +0 -46
- package/src/core/Model.js +0 -86
- package/src/core/QueryParser.js +0 -544
- package/src/handlers/all.js +0 -73
- package/src/handlers/destroy.js +0 -50
- package/src/handlers/helpers.js +0 -320
- package/src/handlers/index.js +0 -9
- package/src/handlers/paginate.js +0 -77
- package/src/handlers/patch.js +0 -95
- package/src/handlers/show.js +0 -81
- package/src/handlers/store.js +0 -82
- package/src/handlers/update.js +0 -92
- package/src/resolvers/checkModelColumns.js +0 -113
- package/src/resolvers/detectDbColumns.js +0 -42
- package/src/resolvers/getModelInstanceArray.js +0 -27
- package/src/resolvers/getModelTree.js +0 -63
- package/src/resolvers/index.js +0 -17
- package/src/resolvers/setExpressRoutes.js +0 -286
- package/src/resolvers/setModelHooks.js +0 -25
- package/src/resolvers/setModelRelations.js +0 -41
package/CHANGELOG.md
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
# Release Notes
|
|
2
|
-
|
|
3
|
-
## [0.19.2 (2022-01-22)](https://github.com/axe-api/axe-api/compare/0.19.2...0.19.1)
|
|
4
|
-
|
|
5
|
-
### Fixed
|
|
6
|
-
|
|
7
|
-
- Fixed the calling `onBeforePaginate` and `onBeforeShow` hooks bug.
|
|
8
|
-
|
|
9
|
-
## [0.19.1 (2022-01-22)](https://github.com/axe-api/axe-api/compare/0.19.1...0.19.0)
|
|
10
|
-
|
|
11
|
-
### Fixed
|
|
12
|
-
|
|
13
|
-
- knex.js version update.
|
|
14
|
-
|
|
15
|
-
## [0.19.0 (2021-12-05)](https://github.com/axe-api/axe-api/compare/0.19.0...0.18.1)
|
|
16
|
-
|
|
17
|
-
### Fixed
|
|
18
|
-
|
|
19
|
-
- [#110](https://github.com/axe-api/axe-api/issues/110)
|
|
20
|
-
|
|
21
|
-
### Enhancements
|
|
22
|
-
|
|
23
|
-
- [#106](https://github.com/axe-api/axe-api/issues/106)
|
|
24
|
-
|
|
25
|
-
## [0.18.1 (2021-12-02)](https://github.com/axe-api/axe-api/compare/0.18.1...0.18.0)
|
|
26
|
-
|
|
27
|
-
### Fixed
|
|
28
|
-
|
|
29
|
-
- [#117](https://github.com/axe-api/axe-api/issues/117)
|
|
30
|
-
|
|
31
|
-
## [0.18.0 (2021-11-30)](https://github.com/axe-api/axe-api/compare/0.18.0...0.17.5)
|
|
32
|
-
|
|
33
|
-
### Fixed
|
|
34
|
-
|
|
35
|
-
- [#115](https://github.com/axe-api/axe-api/issues/115)
|
|
36
|
-
- [#114](https://github.com/axe-api/axe-api/issues/114)
|
|
37
|
-
|
|
38
|
-
### Enhancements
|
|
39
|
-
|
|
40
|
-
- [#113](https://github.com/axe-api/axe-api/issues/113)
|
|
41
|
-
- [#107](https://github.com/axe-api/axe-api/issues/107)
|
|
42
|
-
- [#108](https://github.com/axe-api/axe-api/issues/108)
|
|
43
|
-
|
|
44
|
-
## [0.17.5 (2021-11-27)](https://github.com/axe-api/axe-api/compare/0.17.5...0.17.4)
|
|
45
|
-
|
|
46
|
-
### Fixed
|
|
47
|
-
|
|
48
|
-
- [#111](https://github.com/axe-api/axe-api/issues/111)
|
|
49
|
-
|
|
50
|
-
## [0.17.4 (2021-10-28)](https://github.com/axe-api/axe-api/compare/0.17.4...0.17.3)
|
|
51
|
-
|
|
52
|
-
### Fixed
|
|
53
|
-
|
|
54
|
-
- [#97](https://github.com/axe-api/axe-api/issues/97)
|
|
55
|
-
- [#104](https://github.com/axe-api/axe-api/issues/104)
|
|
56
|
-
|
|
57
|
-
## [0.17.3 (2021-10-28)](https://github.com/axe-api/axe-api/compare/0.17.3...0.17.2)
|
|
58
|
-
|
|
59
|
-
### Fixed
|
|
60
|
-
|
|
61
|
-
- [#98](https://github.com/axe-api/axe-api/issues/98)
|
|
62
|
-
|
|
63
|
-
## [0.17.2 (2021-10-17)](https://github.com/axe-api/axe-api/compare/0.17.2...0.17.1)
|
|
64
|
-
|
|
65
|
-
### Fixed
|
|
66
|
-
|
|
67
|
-
- Fixed table join on the related table filter.
|
|
68
|
-
|
|
69
|
-
## [0.17.1 (2021-10-17)](https://github.com/axe-api/axe-api/compare/0.17.1...0.17.0)
|
|
70
|
-
|
|
71
|
-
### Fixed
|
|
72
|
-
|
|
73
|
-
- Query bug on child models [#93](https://github.com/axe-api/axe-api/issues/93)
|
|
74
|
-
|
|
75
|
-
## [0.17.0 (2021-10-17)](https://github.com/axe-api/axe-api/compare/0.17.0...0.16.0)
|
|
76
|
-
|
|
77
|
-
### Fixed
|
|
78
|
-
|
|
79
|
-
- Related query column name check bug has been fixed.
|
|
80
|
-
|
|
81
|
-
### Features
|
|
82
|
-
|
|
83
|
-
- Global serializer for HTTP results [#37](https://github.com/axe-api/axe-api/issues/37)
|
|
84
|
-
|
|
85
|
-
## [0.16.0 (2021-10-06)](https://github.com/axe-api/axe-api/compare/0.16.0...0.15.0)
|
|
86
|
-
|
|
87
|
-
### Features
|
|
88
|
-
|
|
89
|
-
- Fixes [#89](https://github.com/axe-api/axe-api/issues/89)
|
|
90
|
-
|
|
91
|
-
## [0.15.0 (2021-10-03)](https://github.com/axe-api/axe-api/compare/0.15.0...0.14.1)
|
|
92
|
-
|
|
93
|
-
### Features
|
|
94
|
-
|
|
95
|
-
- Fixes [#87](https://github.com/axe-api/axe-api/issues/87)
|
|
96
|
-
|
|
97
|
-
## [0.14.1 (2021-09-20)](https://github.com/axe-api/axe-api/compare/0.14.1...0.14.0)
|
|
98
|
-
|
|
99
|
-
### Fixed
|
|
100
|
-
|
|
101
|
-
- Fixes [#83](https://github.com/axe-api/axe-api/issues/83)
|
|
102
|
-
|
|
103
|
-
## [0.14.0 (2021-09-15)](https://github.com/axe-api/axe-api/compare/0.14.0...0.13.3)
|
|
104
|
-
|
|
105
|
-
### Features
|
|
106
|
-
|
|
107
|
-
- General hooks definition feature has been added. ([#81](https://github.com/axe-api/axe-api/issues/81))
|
|
108
|
-
|
|
109
|
-
## [0.13.3 (2021-09-15)](https://github.com/axe-api/axe-api/compare/0.13.2...0.13.3)
|
|
110
|
-
|
|
111
|
-
### Fixed
|
|
112
|
-
|
|
113
|
-
- Fixed CORS bugs.
|
|
114
|
-
|
|
115
|
-
## [0.13.2 (2021-08-20)](https://github.com/axe-api/axe-api/compare/0.13.1...0.13.2)
|
|
116
|
-
|
|
117
|
-
### Fixed
|
|
118
|
-
|
|
119
|
-
- Fixes [#27](https://github.com/axe-api/axe-api/issues/27)
|
|
120
|
-
- Fixes [#29](https://github.com/axe-api/axe-api/issues/29)
|
|
121
|
-
- Fixes [#75](https://github.com/axe-api/axe-api/issues/75)
|
|
122
|
-
- Fixes [#78](https://github.com/axe-api/axe-api/issues/78)
|
|
123
|
-
|
|
124
|
-
## [0.13.1 (2021-08-09)](https://github.com/axe-api/axe-api/compare/0.13.0...0.13.1)
|
|
125
|
-
|
|
126
|
-
### Fixed
|
|
127
|
-
|
|
128
|
-
- Fixes [#69](https://github.com/axe-api/axe-api/issues/69)
|
|
129
|
-
- Fixes [#70](https://github.com/axe-api/axe-api/issues/70)
|
|
130
|
-
- Fixes [#71](https://github.com/axe-api/axe-api/issues/71)
|
|
131
|
-
- Fixes [#72](https://github.com/axe-api/axe-api/issues/72)
|
|
132
|
-
|
|
133
|
-
## [0.13.0 (2021-07-25)](https://github.com/axe-api/axe-api/compare/0.12.2...0.13.0)
|
|
134
|
-
|
|
135
|
-
### Features
|
|
136
|
-
|
|
137
|
-
- PostgreSQL database analyzer and integration tests have been added.
|
|
138
|
-
|
|
139
|
-
## [0.12.2 (2021-07-24)](https://github.com/axe-api/axe-api/compare/0.12.1...0.12.2)
|
|
140
|
-
|
|
141
|
-
### Fixed
|
|
142
|
-
|
|
143
|
-
- Throwing an error if the primary key column isn't in the database table bug has been fixed. (#61)[https://github.com/axe-api/axe-api/issues/61]
|
|
144
|
-
- Using numeric column name bug has been fixed. (#24)[https://github.com/axe-api/axe-api/issues/24]
|
|
145
|
-
|
|
146
|
-
## [0.12.1 (2021-07-24)](https://github.com/axe-api/axe-api/compare/0.12.0...0.12.1)
|
|
147
|
-
|
|
148
|
-
### Fixed
|
|
149
|
-
|
|
150
|
-
- Fixed security issues.
|
package/babel.config.cjs
DELETED
package/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import Server from "./src/Server.js";
|
|
2
|
-
import Model from "./src/core/Model.js";
|
|
3
|
-
import IoC from "./src/core/IoC.js";
|
|
4
|
-
import {
|
|
5
|
-
LOG_LEVEL,
|
|
6
|
-
HOOK_FUNCTIONS,
|
|
7
|
-
HANDLERS,
|
|
8
|
-
DEFAULT_HANDLERS,
|
|
9
|
-
} from "./src/constants.js";
|
|
10
|
-
import HttpResponse from "./src/core/HttpResponse.js";
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
Server,
|
|
14
|
-
Model,
|
|
15
|
-
IoC,
|
|
16
|
-
HttpResponse,
|
|
17
|
-
LOG_LEVEL,
|
|
18
|
-
HOOK_FUNCTIONS,
|
|
19
|
-
HANDLERS,
|
|
20
|
-
DEFAULT_HANDLERS,
|
|
21
|
-
};
|
package/jest.config.js
DELETED
package/src/Server.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import dotenv from "dotenv";
|
|
2
|
-
import express from "express";
|
|
3
|
-
import knex from "knex";
|
|
4
|
-
import { attachPaginate } from "knex-paginate";
|
|
5
|
-
import Config from "./core/Config.js";
|
|
6
|
-
import IoC from "./core/IoC.js";
|
|
7
|
-
import Docs from "./core/Docs.js";
|
|
8
|
-
import Logger from "./core/Logger.js";
|
|
9
|
-
import {
|
|
10
|
-
getModelInstanceArray,
|
|
11
|
-
getModelTree,
|
|
12
|
-
setModelRelations,
|
|
13
|
-
setModelHooks,
|
|
14
|
-
setExpressRoutes,
|
|
15
|
-
detectDbColumns,
|
|
16
|
-
checkModelColumns,
|
|
17
|
-
} from "./resolvers/index.js";
|
|
18
|
-
|
|
19
|
-
class Server {
|
|
20
|
-
constructor(appFolder) {
|
|
21
|
-
this.app = null;
|
|
22
|
-
this.appFolder = appFolder;
|
|
23
|
-
this.models = [];
|
|
24
|
-
this.modelTree = [];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async listen() {
|
|
28
|
-
await this._bindDependencies();
|
|
29
|
-
await this._loadConfigurations();
|
|
30
|
-
await this._loadExpress();
|
|
31
|
-
await this._analyzeModels();
|
|
32
|
-
await this._listen();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async _bindDependencies() {
|
|
36
|
-
IoC.singleton("Config", () => new Config());
|
|
37
|
-
IoC.singleton("Database", async () => {
|
|
38
|
-
const Config = await IoC.use("Config");
|
|
39
|
-
const database = knex(Config.Database);
|
|
40
|
-
attachPaginate();
|
|
41
|
-
return database;
|
|
42
|
-
});
|
|
43
|
-
IoC.singleton("App", async () => {
|
|
44
|
-
return express();
|
|
45
|
-
});
|
|
46
|
-
IoC.singleton("Logger", async () => {
|
|
47
|
-
const Config = await IoC.use("Config");
|
|
48
|
-
return new Logger(Config.Application.logLevel);
|
|
49
|
-
});
|
|
50
|
-
IoC.singleton("Docs", async () => new Docs());
|
|
51
|
-
IoC.bind("fs", async () => import("fs"));
|
|
52
|
-
IoC.bind("path", async () => import("path"));
|
|
53
|
-
IoC.bind("url", async () => import("url"));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async _loadConfigurations() {
|
|
57
|
-
dotenv.config();
|
|
58
|
-
const Config = await IoC.use("Config");
|
|
59
|
-
await Config.load(this.appFolder);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async _loadExpress() {
|
|
63
|
-
this.app = await IoC.use("App");
|
|
64
|
-
this.app.use(express.urlencoded({ extended: true }));
|
|
65
|
-
this.app.use(express.json());
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async _analyzeModels() {
|
|
69
|
-
this.models = await getModelInstanceArray(this.appFolder);
|
|
70
|
-
await setModelRelations(this.models);
|
|
71
|
-
await detectDbColumns(this.models);
|
|
72
|
-
checkModelColumns(this.models);
|
|
73
|
-
await setModelHooks("Hooks", this.appFolder, this.models);
|
|
74
|
-
await setModelHooks("Events", this.appFolder, this.models);
|
|
75
|
-
this.modelTree = await getModelTree(this.models);
|
|
76
|
-
await setExpressRoutes(
|
|
77
|
-
this.app,
|
|
78
|
-
this.modelTree,
|
|
79
|
-
this.appFolder,
|
|
80
|
-
this.models
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async _listen() {
|
|
85
|
-
const Config = await IoC.use("Config");
|
|
86
|
-
|
|
87
|
-
this.app.get("/", (req, res) => {
|
|
88
|
-
res.json({
|
|
89
|
-
name: "AXE API",
|
|
90
|
-
description: "The best API creation tool in the world.",
|
|
91
|
-
aim: "To kill them all!",
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
if (Config.Application.env === "development") {
|
|
96
|
-
this.app.get("/docs", async (req, res) => {
|
|
97
|
-
const docs = await IoC.use("Docs");
|
|
98
|
-
res.json({
|
|
99
|
-
routes: docs.get(),
|
|
100
|
-
modelTree: this.modelTree,
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
this.app.get("/docs/routes", async (req, res) => {
|
|
105
|
-
const docs = await IoC.use("Docs");
|
|
106
|
-
res.json(docs.get().map((route) => `${route.method} ${route.url}`));
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
this.app.listen(Config.Application.port, () => {
|
|
111
|
-
console.log(
|
|
112
|
-
`Example app listening at http://localhost:${Config.Application.port}`
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export default Server;
|
package/src/constants.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
const LOG_LEVEL = {
|
|
2
|
-
NONE: 0,
|
|
3
|
-
ERROR: 1,
|
|
4
|
-
WARNING: 2,
|
|
5
|
-
INFO: 3,
|
|
6
|
-
ALL: 4,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const HOOK_FUNCTIONS = {
|
|
10
|
-
onBeforeInsert: "onBeforeInsert",
|
|
11
|
-
onBeforeUpdateQuery: "onBeforeUpdateQuery",
|
|
12
|
-
onBeforeUpdate: "onBeforeUpdate",
|
|
13
|
-
onBeforeDeleteQuery: "onBeforeDeleteQuery",
|
|
14
|
-
onBeforeDelete: "onBeforeDelete",
|
|
15
|
-
onBeforePaginate: "onBeforePaginate",
|
|
16
|
-
onBeforeAll: "onBeforeAll",
|
|
17
|
-
onBeforeShow: "onBeforeShow",
|
|
18
|
-
onAfterInsert: "onAfterInsert",
|
|
19
|
-
onAfterUpdateQuery: "onAfterUpdateQuery",
|
|
20
|
-
onAfterUpdate: "onAfterUpdate",
|
|
21
|
-
onAfterDeleteQuery: "onAfterDeleteQuery",
|
|
22
|
-
onAfterDelete: "onAfterDelete",
|
|
23
|
-
onAfterPaginate: "onAfterPaginate",
|
|
24
|
-
onAfterAll: "onAfterAll",
|
|
25
|
-
onAfterShow: "onAfterShow",
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const RELATIONSHIPS = {
|
|
29
|
-
HAS_ONE: "HAS_ONE",
|
|
30
|
-
HAS_MANY: "HAS_MANY",
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const DEFAULT_METHODS_OF_MODELS = [
|
|
34
|
-
"constructor",
|
|
35
|
-
"hasMany",
|
|
36
|
-
"hasOne",
|
|
37
|
-
"belongsTo",
|
|
38
|
-
"serialize",
|
|
39
|
-
"__defineGetter__",
|
|
40
|
-
"__defineSetter__",
|
|
41
|
-
"hasOwnProperty",
|
|
42
|
-
"__lookupGetter__",
|
|
43
|
-
"__lookupSetter__",
|
|
44
|
-
"isPrototypeOf",
|
|
45
|
-
"propertyIsEnumerable",
|
|
46
|
-
"toString",
|
|
47
|
-
"valueOf",
|
|
48
|
-
"toLocaleString",
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
const HANDLERS = {
|
|
52
|
-
INSERT: "store",
|
|
53
|
-
PAGINATE: "paginate",
|
|
54
|
-
SHOW: "show",
|
|
55
|
-
UPDATE: "update",
|
|
56
|
-
DELETE: "destroy",
|
|
57
|
-
PATCH: "patch",
|
|
58
|
-
ALL: "all",
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const DEFAULT_HANDLERS = [
|
|
62
|
-
HANDLERS.INSERT,
|
|
63
|
-
HANDLERS.PAGINATE,
|
|
64
|
-
HANDLERS.SHOW,
|
|
65
|
-
HANDLERS.UPDATE,
|
|
66
|
-
HANDLERS.PATCH,
|
|
67
|
-
HANDLERS.DELETE,
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
const HTTP_METHODS = {
|
|
71
|
-
POST: "POST",
|
|
72
|
-
GET: "GET",
|
|
73
|
-
PUT: "PUT",
|
|
74
|
-
DELETE: "DELETE",
|
|
75
|
-
PATCH: "PATCH",
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const API_ROUTE_TEMPLATES = {
|
|
79
|
-
[HANDLERS.INSERT]: {
|
|
80
|
-
url: (prefix, parentUrl, resource) => `/${prefix}/${parentUrl}${resource}`,
|
|
81
|
-
method: HTTP_METHODS.POST,
|
|
82
|
-
},
|
|
83
|
-
[HANDLERS.PAGINATE]: {
|
|
84
|
-
url: (prefix, parentUrl, resource) => `/${prefix}/${parentUrl}${resource}`,
|
|
85
|
-
method: HTTP_METHODS.GET,
|
|
86
|
-
},
|
|
87
|
-
[HANDLERS.ALL]: {
|
|
88
|
-
url: (prefix, parentUrl, resource) =>
|
|
89
|
-
`/${prefix}/${parentUrl}${resource}/all`,
|
|
90
|
-
method: HTTP_METHODS.GET,
|
|
91
|
-
},
|
|
92
|
-
[HANDLERS.SHOW]: {
|
|
93
|
-
url: (prefix, parentUrl, resource, primaryKey) =>
|
|
94
|
-
`/${prefix}/${parentUrl}${resource}/:${primaryKey}`,
|
|
95
|
-
method: HTTP_METHODS.GET,
|
|
96
|
-
},
|
|
97
|
-
[HANDLERS.UPDATE]: {
|
|
98
|
-
url: (prefix, parentUrl, resource, primaryKey) =>
|
|
99
|
-
`/${prefix}/${parentUrl}${resource}/:${primaryKey}`,
|
|
100
|
-
method: HTTP_METHODS.PUT,
|
|
101
|
-
},
|
|
102
|
-
[HANDLERS.PATCH]: {
|
|
103
|
-
url: (prefix, parentUrl, resource, primaryKey) =>
|
|
104
|
-
`/${prefix}/${parentUrl}${resource}/:${primaryKey}`,
|
|
105
|
-
method: HTTP_METHODS.PATCH,
|
|
106
|
-
},
|
|
107
|
-
[HANDLERS.DELETE]: {
|
|
108
|
-
url: (prefix, parentUrl, resource, primaryKey) =>
|
|
109
|
-
`/${prefix}/${parentUrl}${resource}/:${primaryKey}`,
|
|
110
|
-
method: HTTP_METHODS.DELETE,
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const LOG_COLORS = {
|
|
115
|
-
fgBlack: "\x1b[30m",
|
|
116
|
-
fgRed: "\x1b[31m",
|
|
117
|
-
fgGreen: "\x1b[32m",
|
|
118
|
-
fgYellow: "\x1b[33m",
|
|
119
|
-
fgBlue: "\x1b[34m",
|
|
120
|
-
fgMagenta: "\x1b[35m",
|
|
121
|
-
fgCyan: "\x1b[36m",
|
|
122
|
-
fgWhite: "\x1b[37m",
|
|
123
|
-
fgReset: "\x1b[0m",
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const DEPENDECY_TYPES = {
|
|
127
|
-
BIND: "BIND",
|
|
128
|
-
SINGLETON: "SINGLETON",
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const TIMESTAMP_COLUMNS = {
|
|
132
|
-
CREATED_AT: "createdAtColumn",
|
|
133
|
-
UPDATED_AT: "updatedAtColumn",
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export {
|
|
137
|
-
LOG_LEVEL,
|
|
138
|
-
HOOK_FUNCTIONS,
|
|
139
|
-
RELATIONSHIPS,
|
|
140
|
-
DEFAULT_METHODS_OF_MODELS,
|
|
141
|
-
HTTP_METHODS,
|
|
142
|
-
API_ROUTE_TEMPLATES,
|
|
143
|
-
LOG_COLORS,
|
|
144
|
-
DEPENDECY_TYPES,
|
|
145
|
-
HANDLERS,
|
|
146
|
-
DEFAULT_HANDLERS,
|
|
147
|
-
TIMESTAMP_COLUMNS,
|
|
148
|
-
};
|
package/src/core/Config.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import url from "url";
|
|
4
|
-
|
|
5
|
-
class Config {
|
|
6
|
-
constructor() {
|
|
7
|
-
this._isLoaded = false;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async load(directory) {
|
|
11
|
-
if (this._isLoaded) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
directory = path.join(directory, "Config");
|
|
16
|
-
const files = fs.readdirSync(directory);
|
|
17
|
-
for (const file of files) {
|
|
18
|
-
const configFile = url.pathToFileURL(path.join(directory, file)).href;
|
|
19
|
-
let { default: configuration } = await import(configFile);
|
|
20
|
-
|
|
21
|
-
if (typeof configuration === "function") {
|
|
22
|
-
configuration = await configuration();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const key = file.replace(".js", "");
|
|
26
|
-
if (key === "load") {
|
|
27
|
-
throw new Error(
|
|
28
|
-
`This is a reserved name. You can not use this name as a configuration file name: "load"`
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this[key] = configuration;
|
|
33
|
-
}
|
|
34
|
-
this._isLoaded = true;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default Config;
|
package/src/core/Docs.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { HTTP_METHODS } from "./../constants.js";
|
|
2
|
-
import { getFormValidation } from "./../handlers/helpers.js";
|
|
3
|
-
|
|
4
|
-
class Docs {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.routes = [];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
push(method, url, model) {
|
|
10
|
-
let fillable = undefined;
|
|
11
|
-
let validations = undefined;
|
|
12
|
-
|
|
13
|
-
if ([HTTP_METHODS.POST, HTTP_METHODS.PUT].includes(method)) {
|
|
14
|
-
// Deteching fillable fields
|
|
15
|
-
if (Array.isArray(model.instance.fillable)) {
|
|
16
|
-
fillable = model.instance.fillable;
|
|
17
|
-
} else {
|
|
18
|
-
fillable = model.instance.fillable[method];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Detecting validations
|
|
22
|
-
if (model.instance.validations) {
|
|
23
|
-
validations = getFormValidation(method, model.instance.validations);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
this.routes.push({
|
|
28
|
-
model: model.name,
|
|
29
|
-
table: model.instance.table,
|
|
30
|
-
columns: model.instance.columns,
|
|
31
|
-
method,
|
|
32
|
-
url,
|
|
33
|
-
fillable,
|
|
34
|
-
validations,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get() {
|
|
39
|
-
return this.routes;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export default Docs;
|
package/src/core/HttpResponse.js
DELETED
package/src/core/IoC.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { DEPENDECY_TYPES } from "./../constants.js";
|
|
2
|
-
|
|
3
|
-
const items = {};
|
|
4
|
-
|
|
5
|
-
const IoC = {
|
|
6
|
-
bind(name, callback) {
|
|
7
|
-
this._add(DEPENDECY_TYPES.BIND, name, callback);
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
singleton(name, callback) {
|
|
11
|
-
this._add(DEPENDECY_TYPES.SINGLETON, name, callback);
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
async use(name) {
|
|
15
|
-
const item = items[name];
|
|
16
|
-
if (!item) {
|
|
17
|
-
throw new Error(`Dependency is not found ${name}`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (item.type === DEPENDECY_TYPES.BIND) {
|
|
21
|
-
return await item.callback();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (item.instance) {
|
|
25
|
-
return item.instance;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
item.instance = await item.callback();
|
|
29
|
-
return item.instance;
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
_add(type, name, callback) {
|
|
33
|
-
items[name] = {
|
|
34
|
-
type,
|
|
35
|
-
callback,
|
|
36
|
-
instance: null,
|
|
37
|
-
};
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export default IoC;
|
package/src/core/Logger.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { LOG_LEVEL, LOG_COLORS } from "./../constants.js";
|
|
2
|
-
const { fgRed, fgGreen, fgYellow, fgCyan, fgReset } = LOG_COLORS;
|
|
3
|
-
|
|
4
|
-
class Logger {
|
|
5
|
-
constructor(level) {
|
|
6
|
-
this.level = level;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
error(message) {
|
|
10
|
-
if (this.level <= LOG_LEVEL.ERROR) {
|
|
11
|
-
console.error(fgRed, "[axe]", message, fgReset);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
warn(message) {
|
|
16
|
-
if (this.level <= LOG_LEVEL.WARNING) {
|
|
17
|
-
console.warn(fgYellow, "[axe]", message, fgReset);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
info(message) {
|
|
22
|
-
if (this.level <= LOG_LEVEL.INFO) {
|
|
23
|
-
console.info(fgCyan, "[axe]", message, fgReset);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
success(message) {
|
|
28
|
-
if (this.level <= LOG_LEVEL.INFO) {
|
|
29
|
-
console.info(fgGreen, "[axe]", message, fgReset);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
log(message) {
|
|
34
|
-
if (this.level === LOG_LEVEL.ALL) {
|
|
35
|
-
console.log(message);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
debug(message) {
|
|
40
|
-
if (this.level === LOG_LEVEL.ALL) {
|
|
41
|
-
console.log(message);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export default Logger;
|