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.
Files changed (126) hide show
  1. package/.eslintrc.json +1 -1
  2. package/bin/not-deploy.js +52 -0
  3. package/index.js +21 -19
  4. package/package.json +1 -1
  5. package/src/app.js +61 -58
  6. package/src/auth/abstract.js +17 -19
  7. package/src/auth/const.js +8 -12
  8. package/src/auth/fields.js +143 -124
  9. package/src/auth/index.js +14 -14
  10. package/src/auth/roles.js +64 -63
  11. package/src/auth/routes.js +89 -54
  12. package/src/auth/rules.js +63 -63
  13. package/src/auth/session.js +60 -62
  14. package/src/bootstrap/form.js +13 -13
  15. package/src/bootstrap/logic.js +45 -41
  16. package/src/bootstrap/model.js +14 -17
  17. package/src/bootstrap/route.js +132 -53
  18. package/src/common.js +86 -79
  19. package/src/core/fields/ID.js +6 -6
  20. package/src/core/fields/__closed.js +3 -3
  21. package/src/core/fields/__latest.js +3 -3
  22. package/src/core/fields/__version.js +3 -3
  23. package/src/core/fields/__versions.js +3 -3
  24. package/src/core/fields/_id.js +6 -6
  25. package/src/core/fields/active.js +9 -9
  26. package/src/core/fields/codeName.js +9 -9
  27. package/src/core/fields/createdAt.js +17 -17
  28. package/src/core/fields/default.js +9 -9
  29. package/src/core/fields/description.js +11 -11
  30. package/src/core/fields/email.js +9 -9
  31. package/src/core/fields/enabled.js +9 -9
  32. package/src/core/fields/expiredAt.js +16 -16
  33. package/src/core/fields/height.js +11 -11
  34. package/src/core/fields/ip.js +10 -10
  35. package/src/core/fields/objectId.js +10 -10
  36. package/src/core/fields/owner.js +13 -13
  37. package/src/core/fields/ownerModel.js +11 -11
  38. package/src/core/fields/price.js +11 -11
  39. package/src/core/fields/requiredObject.js +10 -10
  40. package/src/core/fields/session.js +10 -10
  41. package/src/core/fields/size.js +11 -11
  42. package/src/core/fields/telephone.js +9 -9
  43. package/src/core/fields/title.js +15 -15
  44. package/src/core/fields/updatedAt.js +17 -17
  45. package/src/core/fields/userId.js +11 -12
  46. package/src/core/fields/uuid.js +11 -11
  47. package/src/core/fields/validators/email.js +6 -4
  48. package/src/core/fields/validators/owner.js +6 -4
  49. package/src/core/fields/width.js +11 -11
  50. package/src/domain.js +435 -431
  51. package/src/env.js +23 -23
  52. package/src/error.js +20 -23
  53. package/src/exceptions/db.js +23 -0
  54. package/src/exceptions/http.js +43 -0
  55. package/src/fields/index.js +106 -111
  56. package/src/form/fabric.js +19 -24
  57. package/src/form/form.js +195 -186
  58. package/src/form/index.js +2 -2
  59. package/src/generic/index.js +2 -0
  60. package/src/generic/logic.js +595 -0
  61. package/src/generic/route.js +76 -0
  62. package/src/init/additional.js +7 -7
  63. package/src/init/app.js +75 -68
  64. package/src/init/bodyparser.js +14 -14
  65. package/src/init/compression.js +6 -7
  66. package/src/init/core.js +12 -12
  67. package/src/init/cors.js +22 -24
  68. package/src/init/db/index.js +41 -43
  69. package/src/init/db/ioredis.js +28 -20
  70. package/src/init/db/mongoose.js +42 -32
  71. package/src/init/db/redis.js +59 -48
  72. package/src/init/env.js +44 -36
  73. package/src/init/express.js +18 -21
  74. package/src/init/fileupload.js +8 -10
  75. package/src/init/http.js +65 -47
  76. package/src/init/index.js +141 -148
  77. package/src/init/informer.js +7 -9
  78. package/src/init/methodoverride.js +4 -6
  79. package/src/init/middleware.js +23 -26
  80. package/src/init/modules.js +4 -4
  81. package/src/init/monitoring.js +8 -8
  82. package/src/init/rateLimiter.js +53 -45
  83. package/src/init/routes.js +67 -69
  84. package/src/init/security.js +37 -33
  85. package/src/init/sequence.js +111 -107
  86. package/src/init/sequence.standart.js +54 -56
  87. package/src/init/sessions/index.js +21 -21
  88. package/src/init/sessions/mongoose.js +49 -36
  89. package/src/init/sessions/redis.js +28 -27
  90. package/src/init/static.js +53 -40
  91. package/src/init/template.js +17 -17
  92. package/src/lib.js +230 -200
  93. package/src/manifest/batchRunner.js +26 -25
  94. package/src/manifest/initializator/forms.js +24 -24
  95. package/src/manifest/initializator/index.js +8 -10
  96. package/src/manifest/initializator/manifests.js +45 -42
  97. package/src/manifest/initializator/models.js +37 -34
  98. package/src/manifest/manifest.filter.js +130 -97
  99. package/src/manifest/manifest.js +103 -77
  100. package/src/manifest/module.js +350 -360
  101. package/src/manifest/registrator/fields.js +90 -85
  102. package/src/manifest/registrator/forms.js +47 -47
  103. package/src/manifest/registrator/index.js +14 -16
  104. package/src/manifest/registrator/locales.js +17 -16
  105. package/src/manifest/registrator/logics.js +66 -64
  106. package/src/manifest/registrator/models.js +64 -62
  107. package/src/manifest/registrator/routes.js +171 -132
  108. package/src/manifest/registrator/routes.ws.js +109 -103
  109. package/src/manifest/route.js +216 -161
  110. package/src/model/buildValidator.js +53 -42
  111. package/src/model/default.js +304 -286
  112. package/src/model/enrich.js +69 -61
  113. package/src/model/increment.js +124 -137
  114. package/src/model/proto.js +179 -148
  115. package/src/model/routine.js +85 -76
  116. package/src/model/utils.js +33 -0
  117. package/src/model/versioning.js +148 -130
  118. package/src/obsolete.js +12 -8
  119. package/src/parser.js +29 -22
  120. package/src/repos.js +29 -31
  121. package/src/rollup.js +75 -65
  122. package/src/shell.helpers.js +28 -28
  123. package/static.js +31 -0
  124. package/src/generic/router.js +0 -16
  125. package/src/manifest/module.models.js +0 -0
  126. package/src/manifest/module.status.js +0 -0
@@ -1,190 +1,245 @@
1
+ const CONST_BEFORE_ACTION = "before";
2
+ const CONST_AFTER_ACTION = "after";
1
3
 
2
- const CONST_BEFORE_ACTION = 'before';
3
- const CONST_AFTER_ACTION = 'after';
4
+ const obsoleteWarning = require("../obsolete");
5
+ const Auth = require("../auth"),
6
+ HttpError = require("../error").Http;
4
7
 
5
- const obsoleteWarning = require('../obsolete');
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
- constructor(notApp, moduleName, routeName, actionName, actionData){
22
- this.notApp = notApp;
23
- this.routeName = routeName;
24
- this.moduleName = moduleName;
25
- this.actionName = actionName;
26
- this.actionData = actionData;
27
- return this;
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
- static cycleThruRules(rules, user, url = ''){
50
- for(let i = 0; i < rules.length; i++){
51
- obsoleteWarning(rules[i], url);
52
- if (Auth.checkCredentials(rules[i], user.auth, user.role, user.root)){
53
- return copyObj(rules[i]);
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
- * Select rule from available or return null
61
- * @param {object} req Express Request Object
62
- * @return {object} rule or null
63
- */
64
- selectRule(req){
65
- const user = Auth.extractAuthData(req);
66
- if (this.actionData){
67
- return notRoute.actionAvailableByRule(this.actionData, user);
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
- setRequestRouteData(req, actionName, rule){
74
- req.notRouteData = {
75
- actionName,
76
- rule: copyObj(rule),
77
- actionData: copyObj(this.actionData)
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
- * Executes route action if such exist
83
- * @param {object} req Express Request Object
84
- * @param {object} res Express Response Object
85
- * @param {function} callback
86
- * @return {object} result of execution or HttpError
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
- selectActionName(rule){
113
- let realActionName = this.actionName;
114
- if (rule.actionPrefix){
115
- realActionName = rule.actionPrefix + realActionName;
116
- }else{
117
- if(rule.actionName){
118
- realActionName = rule.actionName;
119
- }else{
120
- if(rule.root || rule.admin /*obsolete*/){
121
- realActionName = '_' + realActionName;
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
- routeIsRunnable(modRoute, actionName){
129
- return (
130
- modRoute &&
131
- objHas(modRoute, actionName) &&
132
- typeof modRoute[actionName] === 'function'
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
- extractReturn(notRouteData){
137
- if(objHas(notRouteData.rule, 'return')){
138
- return [...notRouteData.rule.return];
139
- }else if(objHas(notRouteData.actionData, 'return')){
140
- return [...notRouteData.actionData.return];
141
- }else{
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
- * Removes fields from result object acctoding to actionData.return array
148
- * if presented
149
- * @param {ExpressRequest} req request object
150
- * @param {object} result result returned by main action processor
151
- */
152
- filterResultByReturnRule(req, result){
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
- async executeRoute(modRoute, actionName, {req, res, next}){
165
- try{
166
- //waiting preparation
167
- let prepared = await this.executeFunction(modRoute, CONST_BEFORE_ACTION, [req, res, next]);
168
- //waiting results
169
- let result = await this.executeFunction(modRoute, actionName, [req, res, next, prepared]);
170
- //filter result IF actionData.return specified
171
- this.filterResultByReturnRule(req, result);
172
- //run after with results, continue without waiting when it finished
173
- return this.executeFunction(modRoute, CONST_AFTER_ACTION, [req, res, next, result]);
174
- }catch(e){
175
- next(e);
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
- async executeFunction(obj, name, params) {
180
- let result = params.length > 3 ? params[3]:undefined;
181
- const newResult = await executeObjectFunction(obj, name, params);
182
- if(typeof newResult !== 'undefined'){
183
- return newResult;
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('mongoose-validator');
3
- const {objHas, executeObjectFunction, isFunc, isAsync} = require('../common');
2
+ const validate = require("mongoose-validator");
3
+ const { objHas, executeObjectFunction, isFunc, isAsync } = require("../common");
4
4
 
5
- function extractValidationEnvGetter(options){
6
- if(options && objHas(options, 'getValidationEnv') && isFunc(options.getValidationEnv)){
7
- return options.getValidationEnv;
8
- }else{
9
- //should return at least empty object
10
- return ()=>{return {validate};};
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
- const result = {...rule};
16
- if(objHas(result, 'arguments') && !Array.isArray(result.arguments)){
17
- result.arguments = Object.values(result.arguments);
18
- }
19
- return validate(result);
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
- const result = {...rule};
24
- delete result.validator;
25
- const validationEnv = extractValidationEnvGetter(options)();
26
- if(isAsync(rule.validator)){
27
- result.validator = async (val) => {
28
- return await executeObjectFunction(rule, 'validator', [val, validationEnv]);
29
- };
30
- }else{
31
- result.validator = (val) => {
32
- return executeObjectFunction(rule, 'validator', [val, validationEnv]);
33
- };
34
- }
35
- return result;
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
- function extendValidation(rule, options){
40
- if(typeof rule.validator === 'string'){
41
- //will extend from text description to validatejs lib validation function
42
- return extendObsolete(rule);
43
- }else{
44
- //more complex validation
45
- return extendModern(rule, options);
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
- let result = null;
57
- result = validators.map(rule => extendValidation(rule, options));
58
- return result;
66
+ module.exports = function (validators, options) {
67
+ let result = null;
68
+ result = validators.map((rule) => extendValidation(rule, options));
69
+ return result;
59
70
  };