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
package/src/manifest/route.js
CHANGED
|
@@ -1,190 +1,245 @@
|
|
|
1
|
+
const CONST_BEFORE_ACTION = "before";
|
|
2
|
+
const CONST_AFTER_ACTION = "after";
|
|
1
3
|
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
+
const obsoleteWarning = require("../obsolete");
|
|
5
|
+
const Auth = require("../auth"),
|
|
6
|
+
HttpError = require("../error").Http;
|
|
4
7
|
|
|
5
|
-
const
|
|
6
|
-
const Auth = require('../auth'),
|
|
7
|
-
HttpError = require('../error').Http;
|
|
8
|
-
|
|
9
|
-
const {objHas, copyObj, executeObjectFunction} = require('../common');
|
|
8
|
+
const { objHas, copyObj, executeObjectFunction } = require("../common");
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
|
-
* Route representation
|
|
13
|
-
* @class
|
|
14
|
-
* @param {object} notApp notApplication instance
|
|
15
|
-
* @param {string} moduleName name of owner module
|
|
16
|
-
* @param {string} routeName route name
|
|
17
|
-
* @param {string} actionName action name
|
|
18
|
-
* @param {object} actionData action data
|
|
19
|
-
**/
|
|
20
|
-
class notRoute{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Cycle throu rules of action and checking user credentials against them
|
|
32
|
-
* If user creds comply to some rule - returns copy of rule
|
|
33
|
-
* @param {object} action action rules object
|
|
34
|
-
* @param {object} user user credentials (auth, role, root)
|
|
35
|
-
* @return {object|null} returns rule or null
|
|
36
|
-
**/
|
|
37
|
-
static actionAvailableByRule(action, user){
|
|
38
|
-
if (!action){ return null;}
|
|
39
|
-
if(Array.isArray(action.rules) && action.rules.length > 0){
|
|
40
|
-
return notRoute.cycleThruRules(action.rules, user);
|
|
41
|
-
}else{
|
|
42
|
-
if (Auth.checkCredentials(action, user.auth, user.role, user.root)){
|
|
43
|
-
return copyObj(action);
|
|
44
|
-
}
|
|
11
|
+
* Route representation
|
|
12
|
+
* @class
|
|
13
|
+
* @param {object} notApp notApplication instance
|
|
14
|
+
* @param {string} moduleName name of owner module
|
|
15
|
+
* @param {string} routeName route name
|
|
16
|
+
* @param {string} actionName action name
|
|
17
|
+
* @param {object} actionData action data
|
|
18
|
+
**/
|
|
19
|
+
class notRoute {
|
|
20
|
+
constructor(notApp, moduleName, routeName, actionName, actionData) {
|
|
21
|
+
this.notApp = notApp;
|
|
22
|
+
this.routeName = routeName;
|
|
23
|
+
this.moduleName = moduleName;
|
|
24
|
+
this.actionName = actionName;
|
|
25
|
+
this.actionData = actionData;
|
|
26
|
+
return this;
|
|
45
27
|
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
28
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Cycle throu rules of action and checking user credentials against them
|
|
31
|
+
* If user creds comply to some rule - returns copy of rule
|
|
32
|
+
* @param {object} action action rules object
|
|
33
|
+
* @param {object} user user credentials (auth, role, root)
|
|
34
|
+
* @return {object|null} returns rule or null
|
|
35
|
+
**/
|
|
36
|
+
static actionAvailableByRule(action, user) {
|
|
37
|
+
if (!action) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(action.rules) && action.rules.length > 0) {
|
|
41
|
+
return notRoute.cycleThruRules(action.rules, user);
|
|
42
|
+
} else {
|
|
43
|
+
if (
|
|
44
|
+
Auth.checkCredentials(action, user.auth, user.role, user.root)
|
|
45
|
+
) {
|
|
46
|
+
return copyObj(action);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
55
50
|
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
static cycleThruRules(rules, user, url = "") {
|
|
53
|
+
for (let i = 0; i < rules.length; i++) {
|
|
54
|
+
obsoleteWarning(rules[i], url);
|
|
55
|
+
if (
|
|
56
|
+
Auth.checkCredentials(rules[i], user.auth, user.role, user.root)
|
|
57
|
+
) {
|
|
58
|
+
return copyObj(rules[i]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
68
62
|
}
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
63
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Select rule from available or return null
|
|
66
|
+
* @param {object} req Express Request Object
|
|
67
|
+
* @return {object} rule or null
|
|
68
|
+
*/
|
|
69
|
+
selectRule(req) {
|
|
70
|
+
const user = Auth.extractAuthData(req);
|
|
71
|
+
if (this.actionData) {
|
|
72
|
+
return notRoute.actionAvailableByRule(this.actionData, user);
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
80
76
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
**/
|
|
88
|
-
exec(req, res, next){
|
|
89
|
-
try{
|
|
90
|
-
let rule = this.selectRule(req);
|
|
91
|
-
if (!rule){
|
|
92
|
-
return next(new HttpError(403, ['rule for router not found', this.moduleName, this.routeName].join('; ')));
|
|
93
|
-
}
|
|
94
|
-
obsoleteWarning(rule, req.originalUrl);
|
|
95
|
-
let actionName = this.selectActionName(rule);
|
|
96
|
-
let mod = this.notApp.getModule(this.moduleName);
|
|
97
|
-
if (!mod){
|
|
98
|
-
return next(new HttpError(404, ['module not found', this.moduleName, this.routeName, actionName].join('; ')));
|
|
99
|
-
}
|
|
100
|
-
let modRoute = mod.getRoute(this.routeName);
|
|
101
|
-
this.setRequestRouteData(req, actionName, rule);
|
|
102
|
-
if (this.routeIsRunnable(modRoute, actionName)){
|
|
103
|
-
return this.executeRoute(modRoute, actionName, {req, res, next});
|
|
104
|
-
}else{
|
|
105
|
-
return next(new HttpError(404, ['route not found', this.moduleName, this.routeName, actionName].join('; ')));
|
|
106
|
-
}
|
|
107
|
-
}catch(e){
|
|
108
|
-
this.notApp.report(e);
|
|
77
|
+
setRequestRouteData(req, actionName, rule) {
|
|
78
|
+
req.notRouteData = {
|
|
79
|
+
actionName,
|
|
80
|
+
rule: copyObj(rule),
|
|
81
|
+
actionData: copyObj(this.actionData),
|
|
82
|
+
};
|
|
109
83
|
}
|
|
110
|
-
}
|
|
111
84
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Executes route action if such exist
|
|
87
|
+
* @param {object} req Express Request Object
|
|
88
|
+
* @param {object} res Express Response Object
|
|
89
|
+
* @param {function} callback
|
|
90
|
+
* @return {object} result of execution or HttpError
|
|
91
|
+
**/
|
|
92
|
+
exec(req, res, next) {
|
|
93
|
+
try {
|
|
94
|
+
let rule = this.selectRule(req);
|
|
95
|
+
if (!rule) {
|
|
96
|
+
return next(
|
|
97
|
+
new HttpError(
|
|
98
|
+
403,
|
|
99
|
+
[
|
|
100
|
+
"rule for router not found",
|
|
101
|
+
this.moduleName,
|
|
102
|
+
this.routeName,
|
|
103
|
+
].join("; ")
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
obsoleteWarning(rule, req.originalUrl);
|
|
108
|
+
let actionName = this.selectActionName(rule);
|
|
109
|
+
let mod = this.notApp.getModule(this.moduleName);
|
|
110
|
+
if (!mod) {
|
|
111
|
+
return next(
|
|
112
|
+
new HttpError(
|
|
113
|
+
404,
|
|
114
|
+
[
|
|
115
|
+
"module not found",
|
|
116
|
+
this.moduleName,
|
|
117
|
+
this.routeName,
|
|
118
|
+
actionName,
|
|
119
|
+
].join("; ")
|
|
120
|
+
)
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
let modRoute = mod.getRoute(this.routeName);
|
|
124
|
+
this.setRequestRouteData(req, actionName, rule);
|
|
125
|
+
if (this.routeIsRunnable(modRoute, actionName)) {
|
|
126
|
+
return this.executeRoute(modRoute, actionName, {
|
|
127
|
+
req,
|
|
128
|
+
res,
|
|
129
|
+
next,
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
return next(
|
|
133
|
+
new HttpError(
|
|
134
|
+
404,
|
|
135
|
+
[
|
|
136
|
+
"route not found",
|
|
137
|
+
this.moduleName,
|
|
138
|
+
this.routeName,
|
|
139
|
+
actionName,
|
|
140
|
+
].join("; ")
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
} catch (e) {
|
|
145
|
+
this.notApp.report(e);
|
|
122
146
|
}
|
|
123
|
-
}
|
|
124
147
|
}
|
|
125
|
-
return realActionName;
|
|
126
|
-
}
|
|
127
148
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
149
|
+
selectActionName(rule) {
|
|
150
|
+
let realActionName = this.actionName;
|
|
151
|
+
if (rule.actionPrefix) {
|
|
152
|
+
realActionName = rule.actionPrefix + realActionName;
|
|
153
|
+
} else {
|
|
154
|
+
if (rule.actionName) {
|
|
155
|
+
realActionName = rule.actionName;
|
|
156
|
+
} else {
|
|
157
|
+
if (rule.root || rule.admin /*obsolete*/) {
|
|
158
|
+
realActionName = "_" + realActionName;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return realActionName;
|
|
163
|
+
}
|
|
135
164
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return undefined;
|
|
165
|
+
routeIsRunnable(modRoute, actionName) {
|
|
166
|
+
return (
|
|
167
|
+
modRoute &&
|
|
168
|
+
objHas(modRoute, actionName) &&
|
|
169
|
+
typeof modRoute[actionName] === "function"
|
|
170
|
+
);
|
|
143
171
|
}
|
|
144
|
-
}
|
|
145
172
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const returnList = this.extractReturn(req.notRouteData);
|
|
154
|
-
if(result && (typeof result === 'object') && returnList && Array.isArray(returnList)){
|
|
155
|
-
let presented = Object.keys(result);
|
|
156
|
-
presented.forEach(fieldName => {
|
|
157
|
-
if(!returnList.includes(fieldName)){
|
|
158
|
-
delete result[fieldName];
|
|
173
|
+
extractReturn(notRouteData) {
|
|
174
|
+
if (objHas(notRouteData.rule, "return")) {
|
|
175
|
+
return [...notRouteData.rule.return];
|
|
176
|
+
} else if (objHas(notRouteData.actionData, "return")) {
|
|
177
|
+
return [...notRouteData.actionData.return];
|
|
178
|
+
} else {
|
|
179
|
+
return undefined;
|
|
159
180
|
}
|
|
160
|
-
});
|
|
161
181
|
}
|
|
162
|
-
}
|
|
163
182
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Removes fields from result object acctoding to actionData.return array
|
|
185
|
+
* if presented
|
|
186
|
+
* @param {ExpressRequest} req request object
|
|
187
|
+
* @param {object} result result returned by main action processor
|
|
188
|
+
*/
|
|
189
|
+
filterResultByReturnRule(req, result) {
|
|
190
|
+
const returnList = this.extractReturn(req.notRouteData);
|
|
191
|
+
if (
|
|
192
|
+
result &&
|
|
193
|
+
typeof result === "object" &&
|
|
194
|
+
returnList &&
|
|
195
|
+
Array.isArray(returnList)
|
|
196
|
+
) {
|
|
197
|
+
let presented = Object.keys(result);
|
|
198
|
+
presented.forEach((fieldName) => {
|
|
199
|
+
if (!returnList.includes(fieldName)) {
|
|
200
|
+
delete result[fieldName];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
176
204
|
}
|
|
177
|
-
}
|
|
178
205
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
206
|
+
async executeRoute(modRoute, actionName, { req, res, next }) {
|
|
207
|
+
try {
|
|
208
|
+
//waiting preparation
|
|
209
|
+
let prepared = await this.executeFunction(
|
|
210
|
+
modRoute,
|
|
211
|
+
CONST_BEFORE_ACTION,
|
|
212
|
+
[req, res, next]
|
|
213
|
+
);
|
|
214
|
+
//waiting results
|
|
215
|
+
let result = await this.executeFunction(modRoute, actionName, [
|
|
216
|
+
req,
|
|
217
|
+
res,
|
|
218
|
+
next,
|
|
219
|
+
prepared,
|
|
220
|
+
]);
|
|
221
|
+
//filter result IF actionData.return specified
|
|
222
|
+
this.filterResultByReturnRule(req, result);
|
|
223
|
+
//run after with results, continue without waiting when it finished
|
|
224
|
+
return this.executeFunction(modRoute, CONST_AFTER_ACTION, [
|
|
225
|
+
req,
|
|
226
|
+
res,
|
|
227
|
+
next,
|
|
228
|
+
result,
|
|
229
|
+
]);
|
|
230
|
+
} catch (e) {
|
|
231
|
+
next(e);
|
|
232
|
+
}
|
|
184
233
|
}
|
|
185
|
-
return result;
|
|
186
|
-
}
|
|
187
234
|
|
|
235
|
+
async executeFunction(obj, name, params) {
|
|
236
|
+
let result = params.length > 3 ? params[3] : undefined;
|
|
237
|
+
const newResult = await executeObjectFunction(obj, name, params);
|
|
238
|
+
if (typeof newResult !== "undefined") {
|
|
239
|
+
return newResult;
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
188
243
|
}
|
|
189
244
|
|
|
190
245
|
module.exports = notRoute;
|
|
@@ -1,49 +1,60 @@
|
|
|
1
1
|
/** @module Model/Validator */
|
|
2
|
-
const validate = require(
|
|
3
|
-
const {objHas, executeObjectFunction, isFunc, isAsync} = require(
|
|
2
|
+
const validate = require("mongoose-validator");
|
|
3
|
+
const { objHas, executeObjectFunction, isFunc, isAsync } = require("../common");
|
|
4
4
|
|
|
5
|
-
function extractValidationEnvGetter(options){
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
function extractValidationEnvGetter(options) {
|
|
6
|
+
if (
|
|
7
|
+
options &&
|
|
8
|
+
objHas(options, "getValidationEnv") &&
|
|
9
|
+
isFunc(options.getValidationEnv)
|
|
10
|
+
) {
|
|
11
|
+
return options.getValidationEnv;
|
|
12
|
+
} else {
|
|
13
|
+
//should return at least empty object
|
|
14
|
+
return () => {
|
|
15
|
+
return { validate };
|
|
16
|
+
};
|
|
17
|
+
}
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
function extendObsolete(rule){
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
function extendObsolete(rule) {
|
|
21
|
+
const result = { ...rule };
|
|
22
|
+
if (objHas(result, "arguments") && !Array.isArray(result.arguments)) {
|
|
23
|
+
result.arguments = Object.values(result.arguments);
|
|
24
|
+
}
|
|
25
|
+
return validate(result);
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
function extendModern(rule, options){
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
function extendModern(rule, options) {
|
|
29
|
+
const result = { ...rule };
|
|
30
|
+
delete result.validator;
|
|
31
|
+
const validationEnv = extractValidationEnvGetter(options)();
|
|
32
|
+
if (isAsync(rule.validator)) {
|
|
33
|
+
result.validator = async (val) => {
|
|
34
|
+
return await executeObjectFunction(rule, "validator", [
|
|
35
|
+
val,
|
|
36
|
+
validationEnv,
|
|
37
|
+
]);
|
|
38
|
+
};
|
|
39
|
+
} else {
|
|
40
|
+
result.validator = (val) => {
|
|
41
|
+
return executeObjectFunction(rule, "validator", [
|
|
42
|
+
val,
|
|
43
|
+
validationEnv,
|
|
44
|
+
]);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
36
48
|
}
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
50
|
+
function extendValidation(rule, options) {
|
|
51
|
+
if (typeof rule.validator === "string") {
|
|
52
|
+
//will extend from text description to validatejs lib validation function
|
|
53
|
+
return extendObsolete(rule);
|
|
54
|
+
} else {
|
|
55
|
+
//more complex validation
|
|
56
|
+
return extendModern(rule, options);
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
59
|
|
|
49
60
|
/**
|
|
@@ -52,8 +63,8 @@ function extendValidation(rule, options){
|
|
|
52
63
|
* then return it
|
|
53
64
|
**/
|
|
54
65
|
|
|
55
|
-
module.exports = function(validators, options) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
module.exports = function (validators, options) {
|
|
67
|
+
let result = null;
|
|
68
|
+
result = validators.map((rule) => extendValidation(rule, options));
|
|
69
|
+
return result;
|
|
59
70
|
};
|