axe-api 0.19.1 → 0.20.0-rc10

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.
Files changed (106) hide show
  1. package/build/index.d.ts +8 -0
  2. package/build/index.js +32 -0
  3. package/build/src/Builders/ModelTreeBuilder.d.ts +9 -0
  4. package/build/src/Builders/ModelTreeBuilder.js +64 -0
  5. package/build/src/Builders/RouterBuilder.d.ts +15 -0
  6. package/build/src/Builders/RouterBuilder.js +219 -0
  7. package/build/src/Builders/index.d.ts +3 -0
  8. package/build/src/Builders/index.js +10 -0
  9. package/build/src/Enums.d.ts +77 -0
  10. package/build/src/Enums.js +90 -0
  11. package/build/src/Exceptions/ApiError.d.ts +8 -0
  12. package/build/src/Exceptions/ApiError.js +12 -0
  13. package/build/src/Handlers/AllHandler.d.ts +4 -0
  14. package/build/src/Handlers/AllHandler.js +44 -0
  15. package/build/src/Handlers/DestroyHandler.d.ts +4 -0
  16. package/build/src/Handlers/DestroyHandler.js +37 -0
  17. package/build/src/Handlers/HandlerFactory.d.ts +6 -0
  18. package/build/src/Handlers/HandlerFactory.js +36 -0
  19. package/build/src/Handlers/Helpers.d.ts +14 -0
  20. package/build/src/Handlers/Helpers.js +231 -0
  21. package/build/src/Handlers/PaginateHandler.d.ts +4 -0
  22. package/build/src/Handlers/PaginateHandler.js +48 -0
  23. package/build/src/Handlers/PatchHandler.d.ts +4 -0
  24. package/build/src/Handlers/PatchHandler.js +62 -0
  25. package/build/src/Handlers/ShowHandler.d.ts +4 -0
  26. package/build/src/Handlers/ShowHandler.js +51 -0
  27. package/build/src/Handlers/StoreHandler.d.ts +4 -0
  28. package/build/src/Handlers/StoreHandler.js +59 -0
  29. package/build/src/Handlers/UpdateHandler.d.ts +4 -0
  30. package/build/src/Handlers/UpdateHandler.js +62 -0
  31. package/build/src/Interfaces.d.ts +165 -0
  32. package/build/src/Interfaces.js +3 -0
  33. package/build/src/Model.d.ts +24 -0
  34. package/build/src/Model.js +108 -0
  35. package/build/src/Resolvers/FileResolver.d.ts +5 -0
  36. package/build/src/Resolvers/FileResolver.js +76 -0
  37. package/build/src/Resolvers/FolderResolver.d.ts +5 -0
  38. package/build/src/Resolvers/FolderResolver.js +19 -0
  39. package/build/src/Resolvers/GeneralHookResolver.d.ts +5 -0
  40. package/build/src/Resolvers/GeneralHookResolver.js +35 -0
  41. package/build/src/Resolvers/ModelMiddlewareResolver.d.ts +7 -0
  42. package/build/src/Resolvers/ModelMiddlewareResolver.js +29 -0
  43. package/build/src/Resolvers/ModelResolver.d.ts +9 -0
  44. package/build/src/Resolvers/ModelResolver.js +101 -0
  45. package/build/src/Resolvers/TransactionResolver.d.ts +8 -0
  46. package/build/src/Resolvers/TransactionResolver.js +75 -0
  47. package/build/src/Resolvers/index.d.ts +7 -0
  48. package/build/src/Resolvers/index.js +18 -0
  49. package/build/src/Server.d.ts +8 -0
  50. package/build/src/Server.js +101 -0
  51. package/build/src/Services/DocumentationService.d.ts +9 -0
  52. package/build/src/Services/DocumentationService.js +22 -0
  53. package/build/src/Services/IoCService.d.ts +9 -0
  54. package/build/src/Services/IoCService.js +51 -0
  55. package/build/src/Services/LogService.d.ts +12 -0
  56. package/build/src/Services/LogService.js +41 -0
  57. package/build/src/Services/ModelListService.d.ts +8 -0
  58. package/build/src/Services/ModelListService.js +18 -0
  59. package/build/src/Services/ModelService.d.ts +20 -0
  60. package/build/src/Services/ModelService.js +38 -0
  61. package/build/src/Services/QueryService.d.ts +39 -0
  62. package/build/src/Services/QueryService.js +447 -0
  63. package/build/src/Services/SchemaValidatorService.d.ts +12 -0
  64. package/build/src/Services/SchemaValidatorService.js +114 -0
  65. package/build/src/Services/index.d.ts +8 -0
  66. package/build/src/Services/index.js +20 -0
  67. package/build/src/constants.d.ts +23 -0
  68. package/build/src/constants.js +62 -0
  69. package/package.json +65 -56
  70. package/readme.md +152 -145
  71. package/.eslintrc.cjs +0 -24
  72. package/.github/PULL_REQUEST_TEMPLATE.md +0 -32
  73. package/.github/workflows/auto-tag.yml +0 -15
  74. package/.github/workflows/npm-publish.yml +0 -18
  75. package/.github/workflows/test-integration.yml +0 -29
  76. package/.github/workflows/test-unit.yml +0 -23
  77. package/CHANGELOG.md +0 -144
  78. package/babel.config.cjs +0 -12
  79. package/index.js +0 -21
  80. package/jest.config.js +0 -4
  81. package/src/Server.js +0 -118
  82. package/src/constants.js +0 -148
  83. package/src/core/Config.js +0 -38
  84. package/src/core/Docs.js +0 -43
  85. package/src/core/HttpResponse.js +0 -10
  86. package/src/core/IoC.js +0 -41
  87. package/src/core/Logger.js +0 -46
  88. package/src/core/Model.js +0 -86
  89. package/src/core/QueryParser.js +0 -544
  90. package/src/handlers/all.js +0 -73
  91. package/src/handlers/destroy.js +0 -50
  92. package/src/handlers/helpers.js +0 -320
  93. package/src/handlers/index.js +0 -9
  94. package/src/handlers/paginate.js +0 -77
  95. package/src/handlers/patch.js +0 -95
  96. package/src/handlers/show.js +0 -81
  97. package/src/handlers/store.js +0 -82
  98. package/src/handlers/update.js +0 -92
  99. package/src/resolvers/checkModelColumns.js +0 -113
  100. package/src/resolvers/detectDbColumns.js +0 -42
  101. package/src/resolvers/getModelInstanceArray.js +0 -27
  102. package/src/resolvers/getModelTree.js +0 -63
  103. package/src/resolvers/index.js +0 -17
  104. package/src/resolvers/setExpressRoutes.js +0 -286
  105. package/src/resolvers/setModelHooks.js +0 -25
  106. package/src/resolvers/setModelRelations.js +0 -41
package/CHANGELOG.md DELETED
@@ -1,144 +0,0 @@
1
- # Release Notes
2
-
3
- ## [0.19.1 (2022-01-22)](https://github.com/axe-api/axe-api/compare/0.19.1...0.19.0)
4
-
5
- ### Fixed
6
-
7
- - knex.js version update.
8
-
9
- ## [0.19.0 (2021-12-05)](https://github.com/axe-api/axe-api/compare/0.19.0...0.18.1)
10
-
11
- ### Fixed
12
-
13
- - [#110](https://github.com/axe-api/axe-api/issues/110)
14
-
15
- ### Enhancements
16
-
17
- - [#106](https://github.com/axe-api/axe-api/issues/106)
18
-
19
- ## [0.18.1 (2021-12-02)](https://github.com/axe-api/axe-api/compare/0.18.1...0.18.0)
20
-
21
- ### Fixed
22
-
23
- - [#117](https://github.com/axe-api/axe-api/issues/117)
24
-
25
- ## [0.18.0 (2021-11-30)](https://github.com/axe-api/axe-api/compare/0.18.0...0.17.5)
26
-
27
- ### Fixed
28
-
29
- - [#115](https://github.com/axe-api/axe-api/issues/115)
30
- - [#114](https://github.com/axe-api/axe-api/issues/114)
31
-
32
- ### Enhancements
33
-
34
- - [#113](https://github.com/axe-api/axe-api/issues/113)
35
- - [#107](https://github.com/axe-api/axe-api/issues/107)
36
- - [#108](https://github.com/axe-api/axe-api/issues/108)
37
-
38
- ## [0.17.5 (2021-11-27)](https://github.com/axe-api/axe-api/compare/0.17.5...0.17.4)
39
-
40
- ### Fixed
41
-
42
- - [#111](https://github.com/axe-api/axe-api/issues/111)
43
-
44
- ## [0.17.4 (2021-10-28)](https://github.com/axe-api/axe-api/compare/0.17.4...0.17.3)
45
-
46
- ### Fixed
47
-
48
- - [#97](https://github.com/axe-api/axe-api/issues/97)
49
- - [#104](https://github.com/axe-api/axe-api/issues/104)
50
-
51
- ## [0.17.3 (2021-10-28)](https://github.com/axe-api/axe-api/compare/0.17.3...0.17.2)
52
-
53
- ### Fixed
54
-
55
- - [#98](https://github.com/axe-api/axe-api/issues/98)
56
-
57
- ## [0.17.2 (2021-10-17)](https://github.com/axe-api/axe-api/compare/0.17.2...0.17.1)
58
-
59
- ### Fixed
60
-
61
- - Fixed table join on the related table filter.
62
-
63
- ## [0.17.1 (2021-10-17)](https://github.com/axe-api/axe-api/compare/0.17.1...0.17.0)
64
-
65
- ### Fixed
66
-
67
- - Query bug on child models [#93](https://github.com/axe-api/axe-api/issues/93)
68
-
69
- ## [0.17.0 (2021-10-17)](https://github.com/axe-api/axe-api/compare/0.17.0...0.16.0)
70
-
71
- ### Fixed
72
-
73
- - Related query column name check bug has been fixed.
74
-
75
- ### Features
76
-
77
- - Global serializer for HTTP results [#37](https://github.com/axe-api/axe-api/issues/37)
78
-
79
- ## [0.16.0 (2021-10-06)](https://github.com/axe-api/axe-api/compare/0.16.0...0.15.0)
80
-
81
- ### Features
82
-
83
- - Fixes [#89](https://github.com/axe-api/axe-api/issues/89)
84
-
85
- ## [0.15.0 (2021-10-03)](https://github.com/axe-api/axe-api/compare/0.15.0...0.14.1)
86
-
87
- ### Features
88
-
89
- - Fixes [#87](https://github.com/axe-api/axe-api/issues/87)
90
-
91
- ## [0.14.1 (2021-09-20)](https://github.com/axe-api/axe-api/compare/0.14.1...0.14.0)
92
-
93
- ### Fixed
94
-
95
- - Fixes [#83](https://github.com/axe-api/axe-api/issues/83)
96
-
97
- ## [0.14.0 (2021-09-15)](https://github.com/axe-api/axe-api/compare/0.14.0...0.13.3)
98
-
99
- ### Features
100
-
101
- - General hooks definition feature has been added. ([#81](https://github.com/axe-api/axe-api/issues/81))
102
-
103
- ## [0.13.3 (2021-09-15)](https://github.com/axe-api/axe-api/compare/0.13.2...0.13.3)
104
-
105
- ### Fixed
106
-
107
- - Fixed CORS bugs.
108
-
109
- ## [0.13.2 (2021-08-20)](https://github.com/axe-api/axe-api/compare/0.13.1...0.13.2)
110
-
111
- ### Fixed
112
-
113
- - Fixes [#27](https://github.com/axe-api/axe-api/issues/27)
114
- - Fixes [#29](https://github.com/axe-api/axe-api/issues/29)
115
- - Fixes [#75](https://github.com/axe-api/axe-api/issues/75)
116
- - Fixes [#78](https://github.com/axe-api/axe-api/issues/78)
117
-
118
- ## [0.13.1 (2021-08-09)](https://github.com/axe-api/axe-api/compare/0.13.0...0.13.1)
119
-
120
- ### Fixed
121
-
122
- - Fixes [#69](https://github.com/axe-api/axe-api/issues/69)
123
- - Fixes [#70](https://github.com/axe-api/axe-api/issues/70)
124
- - Fixes [#71](https://github.com/axe-api/axe-api/issues/71)
125
- - Fixes [#72](https://github.com/axe-api/axe-api/issues/72)
126
-
127
- ## [0.13.0 (2021-07-25)](https://github.com/axe-api/axe-api/compare/0.12.2...0.13.0)
128
-
129
- ### Features
130
-
131
- - PostgreSQL database analyzer and integration tests have been added.
132
-
133
- ## [0.12.2 (2021-07-24)](https://github.com/axe-api/axe-api/compare/0.12.1...0.12.2)
134
-
135
- ### Fixed
136
-
137
- - 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]
138
- - Using numeric column name bug has been fixed. (#24)[https://github.com/axe-api/axe-api/issues/24]
139
-
140
- ## [0.12.1 (2021-07-24)](https://github.com/axe-api/axe-api/compare/0.12.0...0.12.1)
141
-
142
- ### Fixed
143
-
144
- - Fixed security issues.
package/babel.config.cjs DELETED
@@ -1,12 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- [
4
- "@babel/preset-env",
5
- {
6
- targets: {
7
- node: "current",
8
- },
9
- },
10
- ],
11
- ],
12
- };
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
@@ -1,4 +0,0 @@
1
- export default {
2
- verbose: true,
3
- modulePathIgnorePatterns: ["tests/integrations"],
4
- };
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
- };
@@ -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;
@@ -1,10 +0,0 @@
1
- class HttpResponse extends Error {
2
- constructor(status, content) {
3
- super(content);
4
- this.type = "HttpResponse";
5
- this.status = status;
6
- this.content = content;
7
- }
8
- }
9
-
10
- export default HttpResponse;
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;
@@ -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;