not-node 5.0.22 → 5.1.2
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/.eslintrc.json +1 -1
- package/bin/not-deploy.js +52 -0
- package/index.js +21 -19
- package/package.json +1 -1
- package/src/app.js +61 -58
- package/src/auth/abstract.js +17 -19
- package/src/auth/const.js +8 -12
- package/src/auth/fields.js +143 -124
- package/src/auth/index.js +14 -14
- package/src/auth/roles.js +64 -63
- package/src/auth/routes.js +89 -54
- package/src/auth/rules.js +63 -63
- package/src/auth/session.js +60 -62
- package/src/bootstrap/form.js +13 -13
- package/src/bootstrap/logic.js +45 -41
- package/src/bootstrap/model.js +14 -17
- package/src/bootstrap/route.js +132 -53
- package/src/common.js +86 -79
- package/src/core/fields/ID.js +6 -6
- package/src/core/fields/__closed.js +3 -3
- package/src/core/fields/__latest.js +3 -3
- package/src/core/fields/__version.js +3 -3
- package/src/core/fields/__versions.js +3 -3
- package/src/core/fields/_id.js +6 -6
- package/src/core/fields/active.js +9 -9
- package/src/core/fields/codeName.js +9 -9
- package/src/core/fields/createdAt.js +17 -17
- package/src/core/fields/default.js +9 -9
- package/src/core/fields/description.js +11 -11
- package/src/core/fields/email.js +9 -9
- package/src/core/fields/enabled.js +9 -9
- package/src/core/fields/expiredAt.js +16 -16
- package/src/core/fields/height.js +11 -11
- package/src/core/fields/ip.js +10 -10
- package/src/core/fields/objectId.js +10 -10
- package/src/core/fields/owner.js +13 -13
- package/src/core/fields/ownerModel.js +11 -11
- package/src/core/fields/price.js +11 -11
- package/src/core/fields/requiredObject.js +10 -10
- package/src/core/fields/session.js +10 -10
- package/src/core/fields/size.js +11 -11
- package/src/core/fields/telephone.js +9 -9
- package/src/core/fields/title.js +15 -15
- package/src/core/fields/updatedAt.js +17 -17
- package/src/core/fields/userId.js +11 -12
- package/src/core/fields/uuid.js +11 -11
- package/src/core/fields/validators/email.js +6 -4
- package/src/core/fields/validators/owner.js +6 -4
- package/src/core/fields/width.js +11 -11
- package/src/domain.js +435 -431
- package/src/env.js +23 -23
- package/src/error.js +20 -23
- package/src/exceptions/db.js +23 -0
- package/src/exceptions/http.js +43 -0
- package/src/fields/index.js +106 -111
- package/src/form/fabric.js +19 -24
- package/src/form/form.js +195 -186
- package/src/form/index.js +2 -2
- package/src/generic/index.js +2 -0
- package/src/generic/logic.js +595 -0
- package/src/generic/route.js +76 -0
- package/src/init/additional.js +7 -7
- package/src/init/app.js +75 -68
- package/src/init/bodyparser.js +14 -14
- package/src/init/compression.js +6 -7
- package/src/init/core.js +12 -12
- package/src/init/cors.js +22 -24
- package/src/init/db/index.js +41 -43
- package/src/init/db/ioredis.js +28 -20
- package/src/init/db/mongoose.js +42 -32
- package/src/init/db/redis.js +59 -48
- package/src/init/env.js +44 -36
- package/src/init/express.js +18 -21
- package/src/init/fileupload.js +8 -10
- package/src/init/http.js +65 -47
- package/src/init/index.js +141 -148
- package/src/init/informer.js +7 -9
- package/src/init/methodoverride.js +4 -6
- package/src/init/middleware.js +23 -26
- package/src/init/modules.js +4 -4
- package/src/init/monitoring.js +8 -8
- package/src/init/rateLimiter.js +53 -45
- package/src/init/routes.js +67 -69
- package/src/init/security.js +37 -33
- package/src/init/sequence.js +111 -107
- package/src/init/sequence.standart.js +54 -56
- package/src/init/sessions/index.js +21 -21
- package/src/init/sessions/mongoose.js +49 -36
- package/src/init/sessions/redis.js +28 -27
- package/src/init/static.js +53 -40
- package/src/init/template.js +17 -17
- package/src/lib.js +230 -200
- package/src/manifest/batchRunner.js +26 -25
- package/src/manifest/initializator/forms.js +24 -24
- package/src/manifest/initializator/index.js +8 -10
- package/src/manifest/initializator/manifests.js +45 -42
- package/src/manifest/initializator/models.js +37 -34
- package/src/manifest/manifest.filter.js +130 -97
- package/src/manifest/manifest.js +103 -77
- package/src/manifest/module.js +350 -360
- package/src/manifest/registrator/fields.js +90 -85
- package/src/manifest/registrator/forms.js +47 -47
- package/src/manifest/registrator/index.js +14 -16
- package/src/manifest/registrator/locales.js +17 -16
- package/src/manifest/registrator/logics.js +66 -64
- package/src/manifest/registrator/models.js +64 -62
- package/src/manifest/registrator/routes.js +171 -132
- package/src/manifest/registrator/routes.ws.js +109 -103
- package/src/manifest/route.js +216 -161
- package/src/model/buildValidator.js +53 -42
- package/src/model/default.js +304 -286
- package/src/model/enrich.js +69 -61
- package/src/model/increment.js +124 -137
- package/src/model/proto.js +179 -148
- package/src/model/routine.js +85 -76
- package/src/model/utils.js +33 -0
- package/src/model/versioning.js +148 -130
- package/src/obsolete.js +12 -8
- package/src/parser.js +29 -22
- package/src/repos.js +29 -31
- package/src/rollup.js +75 -65
- package/src/shell.helpers.js +28 -28
- package/static.js +31 -0
- package/src/generic/router.js +0 -16
- package/src/manifest/module.models.js +0 -0
- package/src/manifest/module.status.js +0 -0
|
@@ -1,47 +1,50 @@
|
|
|
1
|
-
const {notError} = require(
|
|
2
|
-
const {
|
|
3
|
-
const {initManifestFields} = require(
|
|
4
|
-
const {firstLetterToUpper} = require(
|
|
1
|
+
const { notError } = require("not-error");
|
|
2
|
+
const { error } = require("not-log")(module, "initializator");
|
|
3
|
+
const { initManifestFields } = require("../../fields");
|
|
4
|
+
const { firstLetterToUpper } = require("../../common");
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.run({nModule});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
run({nModule}) {
|
|
13
|
-
const moduleName = nModule.getName();
|
|
14
|
-
for(let routeName in nModule.getRoutesManifests()) {
|
|
15
|
-
try{
|
|
16
|
-
const mod = nModule.getRouteManifest(routeName);
|
|
17
|
-
if(mod && Array.isArray(mod.fields)){
|
|
18
|
-
const rawMutationsList = [...mod.fields];
|
|
19
|
-
const ModelName = firstLetterToUpper(mod.model);
|
|
20
|
-
const schema = nModule.getModelSchema(ModelName);
|
|
21
|
-
let privateFields = [];
|
|
22
|
-
if (mod.privateFields){
|
|
23
|
-
privateFields = Array.isArray(mod.privateFields)?[...mod.privateFields]:[];
|
|
24
|
-
delete mod.privateFields;
|
|
25
|
-
}
|
|
26
|
-
mod.fields = initManifestFields(
|
|
27
|
-
nModule.getApp(),
|
|
28
|
-
schema,
|
|
29
|
-
rawMutationsList,
|
|
30
|
-
privateFields,
|
|
31
|
-
moduleName,
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
}catch(e){
|
|
35
|
-
error(`Error while initialization of route: ${moduleName}//${routeName}`);
|
|
36
|
-
if(e instanceof notError){
|
|
37
|
-
error(`name: ${e.options.field}, type: ${e.options.type}`);
|
|
38
|
-
}else{
|
|
39
|
-
error(e);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
6
|
+
const fieldsIsArray = (mod) => mod && Array.isArray(mod.fields);
|
|
7
|
+
const extractPrivateFields = (mod) =>
|
|
8
|
+
Array.isArray(mod.privateFields) ? [...mod.privateFields] : [];
|
|
42
9
|
|
|
10
|
+
module.exports = class notModuleInitializatorManifests {
|
|
11
|
+
static openFile = require;
|
|
12
|
+
constructor({ nModule }) {
|
|
13
|
+
this.run({ nModule });
|
|
43
14
|
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
15
|
|
|
16
|
+
run({ nModule }) {
|
|
17
|
+
const moduleName = nModule.getName();
|
|
18
|
+
for (let routeName in nModule.getRoutesManifests()) {
|
|
19
|
+
try {
|
|
20
|
+
const mod = nModule.getRouteManifest(routeName);
|
|
21
|
+
if (fieldsIsArray(mod)) {
|
|
22
|
+
const rawMutationsList = [...mod.fields];
|
|
23
|
+
const ModelName = firstLetterToUpper(mod.model);
|
|
24
|
+
const schema = nModule.getModelSchema(ModelName);
|
|
25
|
+
let privateFields = [];
|
|
26
|
+
if (mod.privateFields) {
|
|
27
|
+
privateFields = extractPrivateFields(mod);
|
|
28
|
+
delete mod.privateFields;
|
|
29
|
+
}
|
|
30
|
+
mod.fields = initManifestFields(
|
|
31
|
+
nModule.getApp(),
|
|
32
|
+
schema,
|
|
33
|
+
rawMutationsList,
|
|
34
|
+
privateFields,
|
|
35
|
+
moduleName
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
} catch (e) {
|
|
39
|
+
error(
|
|
40
|
+
`Error while initialization of route: ${moduleName}//${routeName}`
|
|
41
|
+
);
|
|
42
|
+
if (e instanceof notError) {
|
|
43
|
+
error(`name: ${e.options.field}, type: ${e.options.type}`);
|
|
44
|
+
} else {
|
|
45
|
+
error(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
47
50
|
};
|
|
@@ -1,39 +1,42 @@
|
|
|
1
|
-
const {
|
|
2
|
-
const protoModel = require(
|
|
3
|
-
const {initFileSchemaFromFields} = require(
|
|
4
|
-
const {notError} = require(
|
|
1
|
+
const { error } = require("not-log")(module, "initializator");
|
|
2
|
+
const protoModel = require("../../model/proto.js");
|
|
3
|
+
const { initFileSchemaFromFields } = require("../../fields");
|
|
4
|
+
const { notError } = require("not-error");
|
|
5
5
|
|
|
6
|
-
module.exports = class notModuleInitializatorModels{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
module.exports = class notModuleInitializatorModels {
|
|
7
|
+
static openFile = require;
|
|
8
|
+
constructor({ nModule }) {
|
|
9
|
+
this.run({ nModule, app: nModule.getApp() });
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
run({ app, nModule }) {
|
|
13
|
+
const moduleName = nModule.getName();
|
|
14
|
+
for (let modelName in nModule.getModels()) {
|
|
15
|
+
try {
|
|
16
|
+
initFileSchemaFromFields({
|
|
17
|
+
app,
|
|
18
|
+
moduleName: nModule.getName(),
|
|
19
|
+
mod: nModule.getModelFile(modelName),
|
|
20
|
+
type: "model",
|
|
21
|
+
from: ":FIELDS",
|
|
22
|
+
to: ":thisSchema",
|
|
23
|
+
});
|
|
24
|
+
protoModel.fabricate(
|
|
25
|
+
nModule.getModelFile(modelName),
|
|
26
|
+
nModule.getOptions(),
|
|
27
|
+
nModule.mongoose
|
|
28
|
+
);
|
|
29
|
+
//log(`${moduleName}//${modelName}`);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
error(
|
|
32
|
+
`Error while initialization of model: ${moduleName}//${modelName}`
|
|
33
|
+
);
|
|
34
|
+
if (e instanceof notError) {
|
|
35
|
+
error(`name: ${e.options.field}, type: ${e.options.type}`);
|
|
36
|
+
} else {
|
|
37
|
+
error(e);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
32
40
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
41
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
42
|
};
|
|
@@ -1,112 +1,145 @@
|
|
|
1
|
-
const merge = require(
|
|
2
|
-
const Auth = require(
|
|
1
|
+
const merge = require("deepmerge");
|
|
2
|
+
const Auth = require("../auth");
|
|
3
3
|
|
|
4
|
-
const DIRTY_FIELDS = [
|
|
4
|
+
const DIRTY_FIELDS = [
|
|
5
|
+
"rules",
|
|
6
|
+
"admin",
|
|
7
|
+
"root",
|
|
8
|
+
"safe",
|
|
9
|
+
"auth",
|
|
10
|
+
"role",
|
|
11
|
+
"actionName",
|
|
12
|
+
"actionPrefix",
|
|
13
|
+
];
|
|
5
14
|
|
|
6
15
|
module.exports = class notManifestFilter {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Clear route from action variants that not permited for user according to
|
|
18
|
+
* his auth, role, root status
|
|
19
|
+
*
|
|
20
|
+
* @param {object} route route object
|
|
21
|
+
* @param {boolean} auth user auth status
|
|
22
|
+
* @param {boolean} role user role status
|
|
23
|
+
* @param {boolean} root user root status
|
|
24
|
+
*
|
|
25
|
+
* @return {object} Return router with only actions user can access with current states of auth, role, root. With removed definitions of what rules of access are.
|
|
26
|
+
**/
|
|
27
|
+
static filterRoute(route, auth, role, root) {
|
|
28
|
+
let result = JSON.parse(JSON.stringify(route));
|
|
29
|
+
result.actions = {};
|
|
30
|
+
if (!route || !route.actions) {
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
for (let actionName in route.actions) {
|
|
34
|
+
if (!route.actions[actionName]) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
let actionSet = route.actions[actionName];
|
|
38
|
+
notManifestFilter.filterRouteAction(
|
|
39
|
+
actionName,
|
|
40
|
+
actionSet,
|
|
41
|
+
auth,
|
|
42
|
+
role,
|
|
43
|
+
root,
|
|
44
|
+
result
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
30
48
|
}
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
49
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
static filterRouteAction(actionName, actionSet, auth, role, root, result) {
|
|
54
|
+
if (Array.isArray(actionSet.rules)) {
|
|
55
|
+
for (let i = 0; i < actionSet.rules.length; i++) {
|
|
56
|
+
if (
|
|
57
|
+
Auth.checkCredentials(actionSet.rules[i], auth, role, root)
|
|
58
|
+
) {
|
|
59
|
+
result.actions[actionName] =
|
|
60
|
+
notManifestFilter.clearActionFromRules(
|
|
61
|
+
actionSet,
|
|
62
|
+
actionSet.rules[i]
|
|
63
|
+
);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
if (Auth.checkCredentials(actionSet, auth, role, root)) {
|
|
69
|
+
result.actions[actionName] =
|
|
70
|
+
notManifestFilter.clearActionFromRules(actionSet);
|
|
71
|
+
}
|
|
43
72
|
}
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
if (Auth.checkCredentials(actionSet, auth, role, root)) {
|
|
47
|
-
result.actions[actionName] = notManifestFilter.clearActionFromRules(actionSet);
|
|
48
|
-
}
|
|
49
73
|
}
|
|
50
|
-
}
|
|
51
74
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Filters manifest for current user auth, role, root.
|
|
77
|
+
* Removes all actions that can not be performed
|
|
78
|
+
*
|
|
79
|
+
* @param {object} manifest full raw manifest
|
|
80
|
+
* @param {boolean} auth user auth status
|
|
81
|
+
* @param {boolean} role user role status
|
|
82
|
+
* @param {boolean} root user root status
|
|
83
|
+
*
|
|
84
|
+
* @return {object} filtered manifest
|
|
85
|
+
**/
|
|
63
86
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
87
|
+
static filter(manifest, auth, role, root) {
|
|
88
|
+
var result = {};
|
|
89
|
+
for (let routeName in manifest) {
|
|
90
|
+
let routeMan = notManifestFilter.filterRoute(
|
|
91
|
+
manifest[routeName],
|
|
92
|
+
auth,
|
|
93
|
+
role,
|
|
94
|
+
root
|
|
95
|
+
);
|
|
96
|
+
if (Object.keys(routeMan.actions).length > 0) {
|
|
97
|
+
result[routeName] = routeMan;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
71
101
|
}
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
102
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
* @return {object} clean action data
|
|
89
|
-
**/
|
|
90
|
-
static clearActionFromRules(action, ruleSet = null) {
|
|
91
|
-
let copy = merge({}, action);
|
|
92
|
-
notManifestFilter.clearFromDirtyFields(copy);
|
|
93
|
-
//copy fields list from rule to action if it exists
|
|
94
|
-
//fields list is used to restrict fields of data that could be accessed via
|
|
95
|
-
//this action
|
|
96
|
-
if (notManifestFilter.ruleSetHasFieldsDirective(ruleSet)) {
|
|
97
|
-
copy.fields = [...ruleSet.fields];
|
|
103
|
+
/**
|
|
104
|
+
* Return true if ruleSet object has not empty list of fields
|
|
105
|
+
* @param {Object} ruleSet specific set of rules for action
|
|
106
|
+
* @return {boolean} if rule set has not empty fields list
|
|
107
|
+
*/
|
|
108
|
+
static ruleSetHasFieldsDirective(ruleSet) {
|
|
109
|
+
return (
|
|
110
|
+
typeof ruleSet !== "undefined" &&
|
|
111
|
+
ruleSet !== null &&
|
|
112
|
+
ruleSet.fields &&
|
|
113
|
+
Array.isArray(ruleSet.fields) &&
|
|
114
|
+
ruleSet.fields.length
|
|
115
|
+
);
|
|
98
116
|
}
|
|
99
|
-
return copy;
|
|
100
|
-
}
|
|
101
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Clear action definition from rules of access
|
|
120
|
+
* @param {object} action action data
|
|
121
|
+
* @param {object} ruleSet specific set of rules for this action
|
|
122
|
+
* @return {object} clean action data
|
|
123
|
+
**/
|
|
124
|
+
static clearActionFromRules(action, ruleSet = null) {
|
|
125
|
+
let copy = merge({}, action);
|
|
126
|
+
notManifestFilter.clearFromDirtyFields(copy);
|
|
127
|
+
//copy fields list from rule to action if it exists
|
|
128
|
+
//fields list is used to restrict fields of data that could be accessed via
|
|
129
|
+
//this action
|
|
130
|
+
if (notManifestFilter.ruleSetHasFieldsDirective(ruleSet)) {
|
|
131
|
+
copy.fields = [...ruleSet.fields];
|
|
132
|
+
}
|
|
133
|
+
return copy;
|
|
134
|
+
}
|
|
102
135
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Deletes fields listed in DIRTY_FIELDS constant from object
|
|
138
|
+
* @param {Object} action action object
|
|
139
|
+
**/
|
|
140
|
+
static clearFromDirtyFields(action) {
|
|
141
|
+
DIRTY_FIELDS.forEach((fieldName) => {
|
|
142
|
+
delete action[fieldName];
|
|
143
|
+
});
|
|
144
|
+
}
|
|
112
145
|
};
|
package/src/manifest/manifest.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
const Parser = require(
|
|
2
|
-
const Route = require(
|
|
1
|
+
const Parser = require("../parser");
|
|
2
|
+
const Route = require("./route");
|
|
3
3
|
|
|
4
|
-
const {objHas}
|
|
5
|
-
|
|
6
|
-
const notManifestFilter = require('./manifest.filter.js');
|
|
4
|
+
const { objHas } = require("../common");
|
|
7
5
|
|
|
6
|
+
const notManifestFilter = require("./manifest.filter.js");
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* API manifest
|
|
@@ -14,86 +13,113 @@ const notManifestFilter = require('./manifest.filter.js');
|
|
|
14
13
|
* @param {string} moduleName name of owner module
|
|
15
14
|
**/
|
|
16
15
|
class notManifest {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
constructor(app, notApp, moduleName) {
|
|
17
|
+
this.app = app;
|
|
18
|
+
this.notApp = notApp;
|
|
19
|
+
this.moduleName = moduleName;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Создаем путь для одной конечной точки
|
|
25
|
+
*
|
|
26
|
+
* @param {object} app express app object
|
|
27
|
+
* @param {string} routesPath directory where routes files is placed
|
|
28
|
+
* @param {string} routeLine aka '/login', '/user/:id', etc
|
|
29
|
+
* @param {string} modelName name of the mongoose model, should be exact as file name with routes for this model. If /models/theme.js contains 'Theme' mongoose model, then /routes/theme.js should `
|
|
30
|
+
* contain routes for that model.
|
|
31
|
+
* @param {string} actionSetName name of action in routes file. Look for existing route file for understanding
|
|
32
|
+
* @param {object} actionData representation of action data
|
|
33
|
+
*
|
|
34
|
+
* @return {boolean} if route were registered
|
|
35
|
+
**/
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
registerRouteForAction(routeLine, routeName, actionName, actionData) {
|
|
38
|
+
if (actionData && actionData.method) {
|
|
39
|
+
const routerAction = new Route(
|
|
40
|
+
this.notApp,
|
|
41
|
+
this.moduleName,
|
|
42
|
+
routeName,
|
|
43
|
+
actionName,
|
|
44
|
+
actionData
|
|
45
|
+
);
|
|
46
|
+
this.app[actionData.method.toLowerCase()](
|
|
47
|
+
routeLine,
|
|
48
|
+
routerAction.exec.bind(routerAction)
|
|
49
|
+
);
|
|
50
|
+
return true;
|
|
51
|
+
} else {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
45
54
|
}
|
|
46
|
-
}
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* Check if manifest file has url, model and actions, so we could register routes
|
|
59
|
-
* @param {object} route content of .manifest.js file
|
|
60
|
-
* @return {boolean} true if could create routes
|
|
61
|
-
**/
|
|
62
|
-
routeHasRoutes(route){
|
|
63
|
-
return objHas(route, 'actions') && objHas(route, 'url') && (objHas(route, 'model') && route.model !== '');
|
|
64
|
-
}
|
|
56
|
+
/**
|
|
57
|
+
* Создаем пути согласно манифесту
|
|
58
|
+
*
|
|
59
|
+
* @param {object} moduleManifest notManifest of module
|
|
60
|
+
**/
|
|
61
|
+
registerRoutes(moduleManifest) {
|
|
62
|
+
Object.values(moduleManifest).forEach((route) =>
|
|
63
|
+
this.registerRoute(route)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if manifest file has url, model and actions, so we could register routes
|
|
69
|
+
* @param {object} route content of .manifest.js file
|
|
70
|
+
* @return {boolean} true if could create routes
|
|
71
|
+
**/
|
|
72
|
+
routeHasRoutes(route) {
|
|
73
|
+
return (
|
|
74
|
+
objHas(route, "actions") &&
|
|
75
|
+
objHas(route, "url") &&
|
|
76
|
+
objHas(route, "model") &&
|
|
77
|
+
route.model !== ""
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Check if manifest file has url and actions, so we could register routes
|
|
83
|
+
* @param {object} moduleManifest library of .manifest.js files
|
|
84
|
+
* @param {string} routeName name of
|
|
85
|
+
**/
|
|
86
|
+
registerRoute(route) {
|
|
87
|
+
if (!this.routeHasRoutes(route)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const routeName = route.model;
|
|
91
|
+
Object.keys(route.actions).forEach((actionName) => {
|
|
92
|
+
const actionData = route.actions[actionName];
|
|
93
|
+
const routeLine = Parser.getRouteLine(
|
|
94
|
+
route.url,
|
|
95
|
+
routeName,
|
|
96
|
+
actionName,
|
|
97
|
+
actionData
|
|
98
|
+
);
|
|
99
|
+
this.registerRouteForAction(
|
|
100
|
+
routeLine,
|
|
101
|
+
routeName,
|
|
102
|
+
actionName,
|
|
103
|
+
actionData
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
92
107
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Filters manifest for current user auth, role, root.
|
|
110
|
+
* Removes all actions that can not be performed
|
|
111
|
+
*
|
|
112
|
+
* @param {object} manifest full raw manifest
|
|
113
|
+
* @param {boolean} auth user auth status
|
|
114
|
+
* @param {boolean} role user role status
|
|
115
|
+
* @param {boolean} root user root status
|
|
116
|
+
*
|
|
117
|
+
* @return {object} filtered manifest
|
|
118
|
+
**/
|
|
96
119
|
|
|
120
|
+
filterManifest(manifest, auth, role, root) {
|
|
121
|
+
return notManifestFilter.filter(manifest, auth, role, root);
|
|
122
|
+
}
|
|
97
123
|
}
|
|
98
124
|
|
|
99
125
|
module.exports = notManifest;
|