axe-api 0.19.0 → 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 -68
- 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 -138
- 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 -77
- 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 -279
- package/src/resolvers/setModelHooks.js +0 -25
- package/src/resolvers/setModelRelations.js +0 -41
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;
|
package/src/core/Model.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import pluralize from "pluralize";
|
|
2
|
-
import { snakeCase } from "snake-case";
|
|
3
|
-
import { RELATIONSHIPS, DEFAULT_HANDLERS } from "./../constants.js";
|
|
4
|
-
|
|
5
|
-
class Model {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.relations = [];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get primaryKey() {
|
|
11
|
-
return "id";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get table() {
|
|
15
|
-
return pluralize(snakeCase(this.constructor.name));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get fillable() {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get validations() {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get handlers() {
|
|
27
|
-
return [...DEFAULT_HANDLERS];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get middlewares() {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get hiddens() {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get createdAtColumn() {
|
|
39
|
-
return "created_at";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get updatedAtColumn() {
|
|
43
|
-
return "updated_at";
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get transaction() {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get ignore() {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
hasMany(relatedModel, primaryKey = "id", foreignKey = null) {
|
|
55
|
-
if (!foreignKey) {
|
|
56
|
-
const currentModelName = pluralize.singular(
|
|
57
|
-
this.constructor.name.toLowerCase()
|
|
58
|
-
);
|
|
59
|
-
foreignKey = `${currentModelName}_id`;
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
type: RELATIONSHIPS.HAS_MANY,
|
|
63
|
-
model: relatedModel,
|
|
64
|
-
primaryKey,
|
|
65
|
-
foreignKey,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
hasOne(relatedModel, primaryKey = "id", foreignKey = null) {
|
|
70
|
-
if (!foreignKey) {
|
|
71
|
-
foreignKey = `${pluralize.singular(relatedModel.toLowerCase())}_id`;
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
type: RELATIONSHIPS.HAS_ONE,
|
|
75
|
-
model: relatedModel,
|
|
76
|
-
primaryKey,
|
|
77
|
-
foreignKey,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
belongsTo(relatedModel, primaryKey, foreignKey) {
|
|
82
|
-
return this.hasOne(relatedModel, foreignKey, primaryKey);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export default Model;
|