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
package/src/form/form.js CHANGED
@@ -1,203 +1,212 @@
1
- const FormFabric = require('./fabric');
1
+ const FormFabric = require("./fabric");
2
2
 
3
- const {
4
- createSchemaFromFields
5
- } = require('../fields');
3
+ const { createSchemaFromFields } = require("../fields");
6
4
 
7
- const {objHas} = require('../common');
5
+ const { objHas } = require("../common");
8
6
 
9
- const ValidationBuilder = require('not-validation').Builder;
10
- const ValidationSession = require('not-validation').Session;
11
-
12
- const {
13
- notValidationError,
14
- notError
15
- } = require('not-error');
7
+ const ValidationBuilder = require("not-validation").Builder;
8
+ const ValidationSession = require("not-validation").Session;
16
9
 
10
+ const { notValidationError, notError } = require("not-error");
17
11
 
18
12
  /**
19
13
  * Generic form validation class
20
14
  **/
21
15
  class Form {
22
- /**
23
- * @prop {SCHEMA} validation schema
24
- **/
25
- #SCHEMA = {
26
- fields: {},
27
- form: []
28
- };
29
- /**
30
- * @prop {string} name of form
31
- **/
32
- #FORM_NAME;
33
- #PROTO_FIELDS;
34
- #VALIDATOR;
35
-
36
- constructor({
37
- FIELDS,
38
- FORM_NAME,
39
- app
40
- }) {
41
- this.#FORM_NAME = FORM_NAME;
42
- this.#PROTO_FIELDS = FIELDS;
43
- this.#createValidationSchema(app);
44
- this.#augmentValidationSchema();
45
- }
46
-
47
- /**
48
- * Extract data from ExpressRequest object and validates it
49
- * returns it or throws
50
- * @param {ExpressRequest} req expressjs request object
51
- * @return {Promise<Object>} form data
52
- * @throws {notValidationError}
53
- **/
54
- async run(req) {
55
- let data = await this.extract(req);
56
- await this.#_validate(data);
57
- return data;
58
- }
59
-
60
- /**
61
- * Extracts data, should be overriden
62
- * @param {ExpressRequest} req expressjs request object
63
- * @return {Object} forma data
64
- **/
65
- async extract( /*req*/ ) {
66
- return {};
67
- }
68
-
69
- /**
70
- * Runs all validation rules against data
71
- * Collects all errors to an object
72
- * if validation failes - returns error object with detail per field description
73
- * of errors
74
- * @param {object} data input data for validation
75
- * @returns {Promise<void>} resolves or throwing notValidationError or notError if reason is unknown
76
- **/
77
- async validate(data){
78
- try{
79
- const validationResult = await ValidationSession(this.#SCHEMA, data);
80
- if(!validationResult.clean){
81
- throw new notValidationError('not-core:form_validation_error', validationResult.getReport(), null, data);
82
- }
83
- }catch(e){
84
- if (e instanceof notValidationError){
85
- throw e;
86
- }else {
87
- throw new notError('not-core:form_validation_unknown_error', {
88
- FORM_NAME: this.#FORM_NAME,
89
- PROTO_FIELDS: this.#PROTO_FIELDS,
90
- FORM_FIELDS: this.getFields(),
91
- message: e.message
92
- }, e);
93
- }
94
- }
95
- }
96
-
97
- //should be overriden
98
- /**
99
- * Returns form specified rules of validation
100
- **/
101
- getFormValidationRules(){
102
- return [];
103
- }
104
-
105
- /**
106
- * Returns function that works as a getter for additional environment variables for
107
- * validators.
108
- * validationFunction(value, additionalEnvVars = {}){}
109
- **/
110
- getValidatorEnvGetter(){
111
- return ()=>{ //should be sync function
112
- return {
113
- env: true //some env variables for validators
114
- };
16
+ /**
17
+ * @prop {SCHEMA} validation schema
18
+ **/
19
+ #SCHEMA = {
20
+ fields: {},
21
+ form: [],
115
22
  };
116
- }
117
-
118
- /**
119
- * Sets validation rules for field
120
- * @param {string} fieldName field name
121
- * @param {Array<Object>} validators validation objects {validator: string|function, message: string}
122
- **/
123
- setValidatorsForField(fieldName, validators){
124
- this.#SCHEMA.fields[fieldName] = validators;
125
- }
126
-
127
- /**
128
- * Returns array of validators
129
- * @return {Arrays<Object>}
130
- **/
131
- getValidatorsForField(fieldName){
132
- return this.#SCHEMA.fields[fieldName];
133
- }
134
-
135
- /**
136
- * Returns list of field names
137
- * @return {Array<string>}
138
- **/
139
- getFields(){
140
- return Object.keys(this.#SCHEMA.fields);
141
- }
142
-
143
-
144
- #createValidationSchema(app){
145
- //creating full model schema
146
- const modelSchema = this.#createModelSchema(app);
147
- //extract fields validation rules
148
- this.#extractValidationSchemaFromModelSchema(modelSchema);
149
- //now form fields and form validation rules is formed in raw form
150
- }
151
-
152
- #createModelSchema(app){
153
- return createSchemaFromFields(app, this.#PROTO_FIELDS, 'model', this.#FORM_NAME);
154
- }
155
-
156
-
157
- #extractValidationSchemaFromModelSchema(modelSchema){
158
- for(let t in modelSchema){
159
- if (objHas(modelSchema[t], 'validate')){
160
- this.setValidatorsForField(t, modelSchema[t].validate);
161
- }
23
+ /**
24
+ * @prop {string} name of form
25
+ **/
26
+ #FORM_NAME;
27
+ #PROTO_FIELDS;
28
+ #VALIDATOR;
29
+
30
+ constructor({ FIELDS, FORM_NAME, app }) {
31
+ this.#FORM_NAME = FORM_NAME;
32
+ this.#PROTO_FIELDS = FIELDS;
33
+ this.#createValidationSchema(app);
34
+ this.#augmentValidationSchema();
35
+ }
36
+
37
+ /**
38
+ * Extract data from ExpressRequest object and validates it
39
+ * returns it or throws
40
+ * @param {ExpressRequest} req expressjs request object
41
+ * @return {Promise<Object>} form data
42
+ * @throws {notValidationError}
43
+ **/
44
+ async run(req) {
45
+ let data = await this.extract(req);
46
+ await this.#_validate(data);
47
+ return data;
48
+ }
49
+
50
+ /**
51
+ * Extracts data, should be overriden
52
+ * @param {ExpressRequest} req expressjs request object
53
+ * @return {Object} forma data
54
+ **/
55
+ async extract(/*req*/) {
56
+ return {};
57
+ }
58
+
59
+ /**
60
+ * Runs all validation rules against data
61
+ * Collects all errors to an object
62
+ * if validation failes - returns error object with detail per field description
63
+ * of errors
64
+ * @param {object} data input data for validation
65
+ * @returns {Promise<void>} resolves or throwing notValidationError or notError if reason is unknown
66
+ **/
67
+ async validate(data) {
68
+ try {
69
+ const validationResult = await ValidationSession(
70
+ this.#SCHEMA,
71
+ data
72
+ );
73
+ if (!validationResult.clean) {
74
+ throw new notValidationError(
75
+ "not-core:form_validation_error",
76
+ validationResult.getReport(),
77
+ null,
78
+ data
79
+ );
80
+ }
81
+ } catch (e) {
82
+ if (e instanceof notValidationError) {
83
+ throw e;
84
+ } else {
85
+ throw new notError(
86
+ "not-core:form_validation_unknown_error",
87
+ {
88
+ FORM_NAME: this.#FORM_NAME,
89
+ PROTO_FIELDS: this.#PROTO_FIELDS,
90
+ FORM_FIELDS: this.getFields(),
91
+ message: e.message,
92
+ },
93
+ e
94
+ );
95
+ }
96
+ }
162
97
  }
163
- this.#SCHEMA.form = this.getFormValidationRules();
164
- }
165
-
166
- #augmentValidationSchema(app){
167
- this.#SCHEMA = ValidationBuilder(this.#SCHEMA, this.getValidatorEnvGetter());
168
- }
169
-
170
- /**
171
- * Validates form data or throws
172
- * @param {Object} data form data
173
- * @return {Object}
174
- * @throws {notValidationError}
175
- **/
176
- async #_validate(data) {
177
- try {
178
- await this.validate(data);
179
- } catch (e) {
180
- if ((e instanceof notError) || (e instanceof notValidationError)){
181
- throw e;
182
- }else {
183
- throw new notError(
184
- 'core:form_validation_error',
185
- {
186
- FORM_NAME: this.#FORM_NAME,
187
- PROTO_FIELDS: this.#PROTO_FIELDS,
188
- FORM_FIELDS: this.getFields(),
189
- data,
190
- message: e.message
191
- },
192
- e
98
+
99
+ //should be overriden
100
+ /**
101
+ * Returns form specified rules of validation
102
+ **/
103
+ getFormValidationRules() {
104
+ return [];
105
+ }
106
+
107
+ /**
108
+ * Returns function that works as a getter for additional environment variables for
109
+ * validators.
110
+ * validationFunction(value, additionalEnvVars = {}){}
111
+ **/
112
+ getValidatorEnvGetter() {
113
+ return () => {
114
+ //should be sync function
115
+ return {
116
+ env: true, //some env variables for validators
117
+ };
118
+ };
119
+ }
120
+
121
+ /**
122
+ * Sets validation rules for field
123
+ * @param {string} fieldName field name
124
+ * @param {Array<Object>} validators validation objects {validator: string|function, message: string}
125
+ **/
126
+ setValidatorsForField(fieldName, validators) {
127
+ this.#SCHEMA.fields[fieldName] = validators;
128
+ }
129
+
130
+ /**
131
+ * Returns array of validators
132
+ * @return {Arrays<Object>}
133
+ **/
134
+ getValidatorsForField(fieldName) {
135
+ return this.#SCHEMA.fields[fieldName];
136
+ }
137
+
138
+ /**
139
+ * Returns list of field names
140
+ * @return {Array<string>}
141
+ **/
142
+ getFields() {
143
+ return Object.keys(this.#SCHEMA.fields);
144
+ }
145
+
146
+ #createValidationSchema(app) {
147
+ //creating full model schema
148
+ const modelSchema = this.#createModelSchema(app);
149
+ //extract fields validation rules
150
+ this.#extractValidationSchemaFromModelSchema(modelSchema);
151
+ //now form fields and form validation rules is formed in raw form
152
+ }
153
+
154
+ #createModelSchema(app) {
155
+ return createSchemaFromFields(
156
+ app,
157
+ this.#PROTO_FIELDS,
158
+ "model",
159
+ this.#FORM_NAME
160
+ );
161
+ }
162
+
163
+ #extractValidationSchemaFromModelSchema(modelSchema) {
164
+ for (let t in modelSchema) {
165
+ if (objHas(modelSchema[t], "validate")) {
166
+ this.setValidatorsForField(t, modelSchema[t].validate);
167
+ }
168
+ }
169
+ this.#SCHEMA.form = this.getFormValidationRules();
170
+ }
171
+
172
+ #augmentValidationSchema() {
173
+ this.#SCHEMA = ValidationBuilder(
174
+ this.#SCHEMA,
175
+ this.getValidatorEnvGetter()
193
176
  );
194
- }
195
177
  }
196
- }
197
178
 
198
- static fabric(){
199
- return FormFabric;
200
- }
179
+ /**
180
+ * Validates form data or throws
181
+ * @param {Object} data form data
182
+ * @return {Object}
183
+ * @throws {notValidationError}
184
+ **/
185
+ async #_validate(data) {
186
+ try {
187
+ await this.validate(data);
188
+ } catch (e) {
189
+ if (e instanceof notError || e instanceof notValidationError) {
190
+ throw e;
191
+ } else {
192
+ throw new notError(
193
+ "core:form_validation_error",
194
+ {
195
+ FORM_NAME: this.#FORM_NAME,
196
+ PROTO_FIELDS: this.#PROTO_FIELDS,
197
+ FORM_FIELDS: this.getFields(),
198
+ data,
199
+ message: e.message,
200
+ },
201
+ e
202
+ );
203
+ }
204
+ }
205
+ }
206
+
207
+ static fabric() {
208
+ return FormFabric;
209
+ }
201
210
  }
202
211
 
203
212
  module.exports = Form;
package/src/form/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  module.exports = {
2
- Form: require('./form'),
3
- FormFabric: require('./fabric'),
2
+ Form: require("./form"),
3
+ FormFabric: require("./fabric"),
4
4
  };
@@ -0,0 +1,2 @@
1
+ module.exports.GenericLogic = require("./logic.js");
2
+ module.exports.GenericRoute = require("./route.js");