not-node 4.0.21 → 5.0.3
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 +2 -7
- package/.idea/codeStyles/Project.xml +16 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/project.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +24 -0
- package/package.json +20 -20
- package/src/app.js +2 -2
- package/src/common.js +5 -1
- package/src/core/config.json +2 -16
- package/src/core/fields/ID.js +2 -2
- package/src/core/fields/__closed.js +5 -0
- package/src/core/fields/__latest.js +5 -0
- package/src/core/fields/__version.js +5 -0
- package/src/core/fields/__versions.js +5 -0
- package/src/core/fields/active.js +1 -1
- package/src/core/fields/codeName.js +2 -2
- package/src/core/fields/createdAt.js +2 -2
- package/src/core/fields/default.js +1 -1
- package/src/core/fields/description.js +2 -2
- package/src/core/fields/email.js +11 -0
- package/src/core/fields/enabled.js +1 -1
- package/src/core/fields/expiredAt.js +2 -2
- package/src/core/fields/height.js +2 -2
- package/src/core/fields/ip.js +2 -2
- package/src/core/fields/objectId.js +13 -0
- package/src/core/fields/owner.js +3 -0
- package/src/core/fields/ownerModel.js +3 -0
- package/src/core/fields/price.js +2 -2
- package/src/core/fields/session.js +2 -2
- package/src/core/fields/size.js +2 -2
- package/src/core/fields/telephone.js +11 -0
- package/src/core/fields/title.js +2 -2
- package/src/core/fields/updatedAt.js +2 -2
- package/src/core/fields/userId.js +2 -2
- package/src/core/fields/uuid.js +2 -2
- package/src/core/fields/validators/email.js +4 -0
- package/src/core/fields/validators/owner.js +1 -1
- package/src/core/fields/width.js +2 -2
- package/src/core/index.js +6 -0
- package/src/core/locales/en.json +6 -0
- package/src/core/locales/ru.json +6 -0
- package/src/domain.js +71 -48
- package/src/fields/.old.js +193 -0
- package/src/fields/index.js +114 -100
- package/src/form/form.js +138 -35
- package/src/init/app.js +8 -1
- package/src/init/db/ioredis.js +0 -1
- package/src/init/index.js +4 -3
- package/src/init/layers/fields.js +7 -0
- package/src/init/layers/forms.js +0 -0
- package/src/init/layers/models.js +0 -0
- package/src/init/layers/routes.js +0 -0
- package/src/init/sequence.standart.js +3 -3
- package/src/manifest/batchRunner.js +33 -0
- package/src/manifest/initializator/forms.js +30 -0
- package/src/manifest/initializator/index.js +24 -0
- package/src/manifest/initializator/manifests.js +47 -0
- package/src/manifest/initializator/models.js +39 -0
- package/src/manifest/module.js +55 -29
- package/src/manifest/registrator/fields.js +17 -16
- package/src/manifest/registrator/forms.js +2 -2
- package/src/manifest/registrator/index.js +3 -27
- package/src/manifest/registrator/locales.js +1 -1
- package/src/manifest/registrator/logics.js +3 -3
- package/src/manifest/registrator/models.js +3 -3
- package/src/manifest/registrator/routes.js +1 -1
- package/src/model/enrich.js +4 -4
- package/src/model/proto.js +0 -1
- package/test/notApp.js +2 -2
package/src/fields/index.js
CHANGED
|
@@ -1,142 +1,156 @@
|
|
|
1
1
|
const clone = require('rfdc')();
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const {
|
|
2
|
+
const notPath = require('not-path');
|
|
3
|
+
const {error} = require('not-log')(module, 'init//fields');
|
|
4
|
+
const {notError} = require('not-error');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const FIELDS = {};
|
|
6
|
+
const {
|
|
7
|
+
objHas,
|
|
8
|
+
} = require('../common');
|
|
12
9
|
|
|
10
|
+
const DEFAULT_TYPE = 'ui';
|
|
11
|
+
const DEFAULT_FROM = ':FIELDS';
|
|
12
|
+
const DEFAULT_TO = ':thisSchema';
|
|
13
13
|
|
|
14
|
-
module.exports.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
registerField(parts.name, require(fromPath), {overwrite, compose});
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const registerField = module.exports.registerField = (name, value, {overwrite = false, compose = true} = DEFAULT_FIELD_REGISTRATION_RULES)=>{
|
|
24
|
-
if(objHas(FIELDS, name)){
|
|
25
|
-
if(overwrite){
|
|
26
|
-
FIELDS[name] = value;
|
|
27
|
-
}else if(compose){
|
|
28
|
-
Object.assign(FIELDS[name], value);
|
|
29
|
-
}
|
|
30
|
-
}else{
|
|
31
|
-
FIELDS[name] = value;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
module.exports.registerFields = (fields, {overwrite = false, compose = true})=>{
|
|
36
|
-
for(let t in fields){
|
|
37
|
-
module.exports.registerField(t, fields[t], {overwrite, compose});
|
|
14
|
+
module.exports.initFileSchemaFromFields = ({app, mod, type = DEFAULT_TYPE, from = DEFAULT_FROM, to = DEFAULT_TO, moduleName = ''})=>{
|
|
15
|
+
const FIELDS = notPath.get(from, mod);
|
|
16
|
+
if(FIELDS && Array.isArray(FIELDS)){
|
|
17
|
+
const schema = module.exports.createSchemaFromFields(app, FIELDS, type, moduleName);
|
|
18
|
+
notPath.set(to, mod, schema);
|
|
38
19
|
}
|
|
39
20
|
};
|
|
40
21
|
|
|
41
22
|
/**
|
|
42
|
-
|
|
23
|
+
fields = [
|
|
43
24
|
'title', //for standart only name
|
|
44
25
|
['titleNonStandart', {component: 'UITextforBlind'}] //arrays of [name, mutation]
|
|
45
26
|
['someID', {}, 'ID'], //copy of standart ID field under name as someID
|
|
46
27
|
]
|
|
47
|
-
|
|
48
|
-
module.exports.
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
let
|
|
52
|
-
|
|
28
|
+
**/
|
|
29
|
+
module.exports.createSchemaFromFields = (app, fields, type = 'ui', moduleName) => {
|
|
30
|
+
let schema = {};
|
|
31
|
+
fields.forEach((field) => {
|
|
32
|
+
let [schemaFieldName, schemaFieldValue] = module.exports.initSchemaField(app, field, false, type, moduleName);
|
|
33
|
+
schema[schemaFieldName] = schemaFieldValue;
|
|
53
34
|
});
|
|
54
|
-
return
|
|
35
|
+
return schema;
|
|
55
36
|
};
|
|
56
37
|
|
|
57
38
|
|
|
39
|
+
module.exports.initSchemaField = (app, field, resultOnly = true, type = 'ui', moduleName) => {
|
|
40
|
+
//log(field);
|
|
41
|
+
let {
|
|
42
|
+
srcName,
|
|
43
|
+
destName,
|
|
44
|
+
mutation
|
|
45
|
+
} = parseFieldDescription(field);
|
|
46
|
+
let proto = findFieldPrototype(app, srcName, type);
|
|
47
|
+
if(!proto){
|
|
48
|
+
error(`field ${moduleName}//${destName} prototype ${srcName} of ${type} type is not found`);
|
|
49
|
+
}
|
|
50
|
+
let schemaFieldValue = Object.assign({}, clone(proto), mutation);
|
|
51
|
+
if (resultOnly) {
|
|
52
|
+
return schemaFieldValue;
|
|
53
|
+
} else {
|
|
54
|
+
return [destName, schemaFieldValue];
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
field: string - just name of the field
|
|
65
|
-
field: Array - [destinationField:string, mutation: Object, sourceField:string]
|
|
66
|
-
field: Array - [sourceField:string, mutation: Object]
|
|
67
|
-
sourceField - standart field to extend
|
|
68
|
-
mutation - to extend by
|
|
69
|
-
destinationField - name of resulting field,
|
|
70
|
-
if no dest then src will be used
|
|
71
|
-
* @param {boolean} resultOnly return only result, if false then returns [name, value]
|
|
72
|
-
* @param {string} type type of field information
|
|
59
|
+
* field form
|
|
60
|
+
* 'destFieldNameSameAsSourceFieldName' - form 1
|
|
61
|
+
* ['destFieldName', {full: true, field: 'content'}] - form 2
|
|
62
|
+
* ['destFieldName', 'srcFieldName'] //field alias, form 3
|
|
63
|
+
* ['destFieldName', {mutation: 'content'}, 'srcFieldName']// - form 4
|
|
73
64
|
**/
|
|
74
|
-
|
|
75
|
-
let srcName,
|
|
65
|
+
const parseFieldDescription = (field) => {
|
|
66
|
+
let srcName,
|
|
67
|
+
destName,
|
|
68
|
+
mutation = {};
|
|
76
69
|
if (Array.isArray(field)) {
|
|
77
70
|
destName = srcName = field[0];
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
if(field.length === 2){
|
|
72
|
+
if(typeof field[1] === 'string'){
|
|
73
|
+
srcName = field[1]; //form 3
|
|
74
|
+
}else{
|
|
75
|
+
mutation = field[1]; //form 2
|
|
76
|
+
}
|
|
77
|
+
}else if (field.length === 3) { //form 4
|
|
78
|
+
mutation = field[1];
|
|
80
79
|
srcName = field[2];
|
|
81
80
|
}
|
|
82
81
|
} else {
|
|
83
|
-
destName = srcName = field;
|
|
84
|
-
}
|
|
85
|
-
let proto = (objHas(FIELDS, srcName) && objHas(FIELDS[srcName], type)) ? FIELDS[srcName][type]:{};
|
|
86
|
-
let result = Object.assign({}, clone(proto), mutation);
|
|
87
|
-
if (resultOnly) {
|
|
88
|
-
return result;
|
|
89
|
-
} else {
|
|
90
|
-
return [destName, result];
|
|
82
|
+
destName = srcName = field; //form 1
|
|
91
83
|
}
|
|
84
|
+
return {
|
|
85
|
+
srcName,
|
|
86
|
+
destName,
|
|
87
|
+
mutation
|
|
88
|
+
};
|
|
92
89
|
};
|
|
93
90
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
function getMutationForField(name, list) {
|
|
101
|
-
for(let item of list){
|
|
102
|
-
if (Array.isArray(item) && item[0] === name) {
|
|
103
|
-
return item;
|
|
104
|
-
}
|
|
91
|
+
const findFieldPrototype = (app, name, type) => {
|
|
92
|
+
const fieldPrototype = app.getField(name);
|
|
93
|
+
if(fieldPrototype && objHas(fieldPrototype, type)){
|
|
94
|
+
return fieldPrototype[type];
|
|
95
|
+
}else{
|
|
96
|
+
return null;
|
|
105
97
|
}
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
module.exports.getMutationForField = getMutationForField;
|
|
98
|
+
};
|
|
109
99
|
|
|
110
100
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @param {
|
|
116
|
-
* @param {Array}
|
|
117
|
-
* @
|
|
101
|
+
* Creates fields UI representation schema from list of fields in DB model
|
|
102
|
+
* and library of fields
|
|
103
|
+
* @param {object} app notApplication instance
|
|
104
|
+
* @param {object} schema model db schema
|
|
105
|
+
* @param {Array<string|Array>} rawMutationsList fields mutations, for little tuning
|
|
106
|
+
* @param {Array<string>} privateFields fields to omit from result
|
|
107
|
+
* @param {string} moduleName for detailed reports on issues, in which module and what field is faulty
|
|
108
|
+
* @returns {object} resulting UI rendering schema for fields
|
|
118
109
|
**/
|
|
119
|
-
|
|
110
|
+
|
|
111
|
+
module.exports.initManifestFields = (
|
|
112
|
+
app, //notApplication
|
|
113
|
+
schema, //schema of model
|
|
114
|
+
rawMutationsList = [], //fields mutations
|
|
115
|
+
privateFields = [], //fields to omit
|
|
116
|
+
moduleName //module name for reporting
|
|
117
|
+
) => {
|
|
120
118
|
let
|
|
121
119
|
//shallow copy of array
|
|
122
120
|
mutationsList = [...rawMutationsList],
|
|
123
121
|
list = [];
|
|
124
122
|
if (schema && Object.keys(schema).length > 0) {
|
|
125
123
|
let rawKeys = Object.keys(schema);
|
|
126
|
-
rawKeys
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
124
|
+
rawKeys
|
|
125
|
+
.filter((key) => !privateFields.includes(key))
|
|
126
|
+
.forEach((key) => {
|
|
127
|
+
let mutation = getMutationForField(key, mutationsList);
|
|
128
|
+
if (mutation) {
|
|
129
|
+
list.push(mutation);
|
|
130
|
+
mutationsList.splice(mutationsList.indexOf(mutation), 1);
|
|
131
|
+
} else {
|
|
132
|
+
list.push(key);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
135
|
list.push(...mutationsList);
|
|
136
|
-
return module.exports.
|
|
136
|
+
return module.exports.createSchemaFromFields(app, list, 'ui', moduleName);
|
|
137
137
|
}else{
|
|
138
138
|
return {};
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Returns mutation tuple for a field or false
|
|
144
|
+
* @param {string} name field name
|
|
145
|
+
* @param {Array} list fields description lists
|
|
146
|
+
* @return {boolean|item}
|
|
147
|
+
*/
|
|
148
|
+
function getMutationForField(name, list) {
|
|
149
|
+
for(let item of list){
|
|
150
|
+
if (Array.isArray(item) && item[0] === name) {
|
|
151
|
+
return item;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
module.exports.getMutationForField = getMutationForField;
|
package/src/form/form.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
//DB related validation tools
|
|
2
|
-
const mongoose = require('mongoose');
|
|
3
|
-
const Schema = mongoose.Schema;
|
|
4
|
-
//not-node
|
|
5
|
-
const initFields = require('../fields').initFields;
|
|
6
|
-
|
|
7
1
|
const FormFabric = require('./fabric');
|
|
8
2
|
|
|
3
|
+
const {
|
|
4
|
+
createSchemaFromFields
|
|
5
|
+
} = require('../fields');
|
|
6
|
+
|
|
9
7
|
const {
|
|
10
8
|
byFieldsValidators
|
|
11
9
|
} = require('../model/enrich');
|
|
12
10
|
|
|
11
|
+
const {objHas} = require('../common');
|
|
12
|
+
|
|
13
|
+
const ValidationBuilder = require('not-validation').Builder;
|
|
14
|
+
const ValidationSession = require('not-validation').Session;
|
|
15
|
+
|
|
13
16
|
const {
|
|
14
17
|
notValidationError,
|
|
15
18
|
notError
|
|
@@ -20,23 +23,29 @@ const {
|
|
|
20
23
|
* Generic form validation class
|
|
21
24
|
**/
|
|
22
25
|
class Form {
|
|
26
|
+
/**
|
|
27
|
+
* @prop {SCHEMA} validation schema
|
|
28
|
+
**/
|
|
29
|
+
#SCHEMA = {
|
|
30
|
+
fields: {},
|
|
31
|
+
form: []
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @prop {string} name of form
|
|
35
|
+
**/
|
|
36
|
+
#FORM_NAME;
|
|
37
|
+
#PROTO_FIELDS;
|
|
38
|
+
#VALIDATOR;
|
|
39
|
+
|
|
23
40
|
constructor({
|
|
24
41
|
FIELDS,
|
|
25
|
-
FORM_NAME
|
|
42
|
+
FORM_NAME,
|
|
43
|
+
app
|
|
26
44
|
}) {
|
|
27
|
-
this
|
|
28
|
-
this
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.MODEL = mongoose.model(FORM_NAME, Schema(this.SCHEMA));
|
|
32
|
-
}else{
|
|
33
|
-
this.MODEL = mongoose.connection.model(FORM_NAME);
|
|
34
|
-
this.SCHEMA = this.MODEL.schema;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getFields(){
|
|
39
|
-
return Object.keys(this.SCHEMA);
|
|
45
|
+
this.#FORM_NAME = FORM_NAME;
|
|
46
|
+
this.#PROTO_FIELDS = FIELDS;
|
|
47
|
+
this.#createValidationSchema(app);
|
|
48
|
+
this.#augmentValidationSchema();
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
/**
|
|
@@ -48,7 +57,7 @@ class Form {
|
|
|
48
57
|
**/
|
|
49
58
|
async run(req) {
|
|
50
59
|
let data = await this.extract(req);
|
|
51
|
-
await this
|
|
60
|
+
await this.#_validate(data);
|
|
52
61
|
return data;
|
|
53
62
|
}
|
|
54
63
|
|
|
@@ -61,30 +70,128 @@ class Form {
|
|
|
61
70
|
return {};
|
|
62
71
|
}
|
|
63
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Runs all validation rules against data
|
|
75
|
+
* Collects all errors to an object
|
|
76
|
+
* if validation failes - returns error object with detail per field description
|
|
77
|
+
* of errors
|
|
78
|
+
* @param {object} data input data for validation
|
|
79
|
+
* @returns {Promise<void>} resolves or throwing notValidationError or notError if reason is unknown
|
|
80
|
+
**/
|
|
81
|
+
async validate(data){
|
|
82
|
+
try{
|
|
83
|
+
const validationResult = await ValidationSession(this.#SCHEMA, data);
|
|
84
|
+
if(!validationResult.clean){
|
|
85
|
+
throw new notValidationError('not-core:form_validation_error', validationResult.getReport(), null, data);
|
|
86
|
+
}
|
|
87
|
+
}catch(e){
|
|
88
|
+
if (e instanceof notValidationError){
|
|
89
|
+
throw e;
|
|
90
|
+
}else {
|
|
91
|
+
throw new notError('not-core:form_validation_unknown_error', {
|
|
92
|
+
FORM_NAME: this.#FORM_NAME,
|
|
93
|
+
PROTO_FIELDS: this.#PROTO_FIELDS,
|
|
94
|
+
FORM_FIELDS: this.getFields(),
|
|
95
|
+
message: e.message
|
|
96
|
+
}, e);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//should be overriden
|
|
102
|
+
/**
|
|
103
|
+
* Returns form specified rules of validation
|
|
104
|
+
**/
|
|
105
|
+
getFormValidationRules(){
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Returns function that works as a getter for additional environment variables for
|
|
111
|
+
* validators.
|
|
112
|
+
* validationFunction(value, additionalEnvVars = {}){}
|
|
113
|
+
**/
|
|
114
|
+
getValidatorEnvGetter(){
|
|
115
|
+
return ()=>{ //should be sync function
|
|
116
|
+
return {
|
|
117
|
+
env: true //some env variables for validators
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Sets validation rules for field
|
|
124
|
+
* @param {string} fieldName field name
|
|
125
|
+
* @param {Array<Object>} validators validation objects {validator: string|function, message: string}
|
|
126
|
+
**/
|
|
127
|
+
setValidatorsForField(fieldName, validators){
|
|
128
|
+
this.#SCHEMA.fields[fieldName] = validators;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Returns array of validators
|
|
133
|
+
* @return {Arrays<Object>}
|
|
134
|
+
**/
|
|
135
|
+
getValidatorsForField(fieldName){
|
|
136
|
+
return this.#SCHEMA.fields[fieldName];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Returns list of field names
|
|
141
|
+
* @return {Array<string>}
|
|
142
|
+
**/
|
|
143
|
+
getFields(){
|
|
144
|
+
return Object.keys(this.#SCHEMA.fields);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
#createValidationSchema(app){
|
|
149
|
+
//creating full model schema
|
|
150
|
+
const modelSchema = this.#createModelSchema(app);
|
|
151
|
+
//extract fields validation rules
|
|
152
|
+
this.#extractValidationSchemaFromModelSchema(modelSchema);
|
|
153
|
+
//now form fields and form validation rules is formed in raw form
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
#createModelSchema(app){
|
|
157
|
+
return byFieldsValidators(
|
|
158
|
+
createSchemaFromFields(app, this.#PROTO_FIELDS, 'model', this.#FORM_NAME)
|
|
159
|
+
);
|
|
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(app){
|
|
173
|
+
this.#SCHEMA = ValidationBuilder(this.#SCHEMA, this.getValidatorEnvGetter());
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
64
177
|
/**
|
|
65
178
|
* Validates form data or throws
|
|
66
179
|
* @param {Object} data form data
|
|
67
180
|
* @return {Object}
|
|
68
181
|
* @throws {notValidationError}
|
|
69
182
|
**/
|
|
70
|
-
async _validate(data) {
|
|
183
|
+
async #_validate(data) {
|
|
71
184
|
try {
|
|
72
185
|
await this.validate(data);
|
|
73
186
|
} catch (e) {
|
|
74
|
-
|
|
75
|
-
if (e instanceof mongoose.Error.ValidationError) {
|
|
76
|
-
Object.keys(e.errors).forEach(name => {
|
|
77
|
-
fields[name] = [e.errors[name].message];
|
|
78
|
-
});
|
|
79
|
-
throw new notValidationError(e.message, fields, e, data);
|
|
80
|
-
} else if (e instanceof notValidationError){
|
|
187
|
+
if ((e instanceof notError) || (e instanceof notValidationError)){
|
|
81
188
|
throw e;
|
|
82
189
|
}else {
|
|
83
190
|
throw new notError(
|
|
84
191
|
'core:form_validation_error',
|
|
85
192
|
{
|
|
86
|
-
FORM_NAME: this
|
|
87
|
-
PROTO_FIELDS: this
|
|
193
|
+
FORM_NAME: this.#FORM_NAME,
|
|
194
|
+
PROTO_FIELDS: this.#PROTO_FIELDS,
|
|
88
195
|
FORM_FIELDS: this.getFields(),
|
|
89
196
|
data,
|
|
90
197
|
message: e.message
|
|
@@ -95,10 +202,6 @@ class Form {
|
|
|
95
202
|
}
|
|
96
203
|
}
|
|
97
204
|
|
|
98
|
-
async validate(data){
|
|
99
|
-
await this.MODEL.validate(data, this.getFields());
|
|
100
|
-
}
|
|
101
|
-
|
|
102
205
|
static fabric(){
|
|
103
206
|
return FormFabric;
|
|
104
207
|
}
|
package/src/init/app.js
CHANGED
|
@@ -11,7 +11,7 @@ const emit = require('./additional').run;
|
|
|
11
11
|
|
|
12
12
|
module.exports = class InitApp{
|
|
13
13
|
static AppConstructor = notAppConstructor;
|
|
14
|
-
static ReporterConstructor = notErrorReporter
|
|
14
|
+
static ReporterConstructor = notErrorReporter;
|
|
15
15
|
|
|
16
16
|
static async createApp({config, options, master}){
|
|
17
17
|
await emit('app.create.pre', {config, options, master});
|
|
@@ -32,6 +32,12 @@ module.exports = class InitApp{
|
|
|
32
32
|
await emit('app.setEnv.post', {config, options, master});
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
static async initCore({config, options, master}){
|
|
36
|
+
await emit('app.initCore.pre', {config, options, master});
|
|
37
|
+
master.getApp().importModuleFrom(path.join(__dirname, '../core'));
|
|
38
|
+
await emit('app.initCore.post', {config, options, master});
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
static async importModules({config, options, master}){
|
|
36
42
|
await emit('app.importModules.pre', {config, options, master});
|
|
37
43
|
master.getApp().importModulesFrom(config.get('modulesPath'));
|
|
@@ -62,6 +68,7 @@ module.exports = class InitApp{
|
|
|
62
68
|
await emit('app.pre', {config, options, master});
|
|
63
69
|
await InitApp.createApp({config, options, master});
|
|
64
70
|
await InitApp.setAppEnvs({config, options, master});
|
|
71
|
+
await InitApp.initCore({config, options, master});
|
|
65
72
|
await InitApp.importModules({config, options, master});
|
|
66
73
|
await InitApp.createReporter({config, options, master});
|
|
67
74
|
await emit('app.post', {config, options, master});
|
package/src/init/db/ioredis.js
CHANGED
package/src/init/index.js
CHANGED
|
@@ -108,7 +108,7 @@ class Init {
|
|
|
108
108
|
static printOutManifest = () => {
|
|
109
109
|
log.debug('Manifest:');
|
|
110
110
|
log.debug(JSON.stringify(Init.notApp.getManifest(), null, 4));
|
|
111
|
-
}
|
|
111
|
+
};
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
114
|
* Initalization of Application
|
|
@@ -127,7 +127,7 @@ class Init {
|
|
|
127
127
|
additional
|
|
128
128
|
}) {
|
|
129
129
|
try {
|
|
130
|
-
log.info('Kick start app...'+ os.platform()+os.arch());
|
|
130
|
+
log.info('Kick start app...'+ os.platform()+' '+os.arch());
|
|
131
131
|
ADDS.init(additional);
|
|
132
132
|
const initSequence = new InitSequence(STANDART_INIT_SEQUENCE);
|
|
133
133
|
await ADDS.run('pre', {
|
|
@@ -153,7 +153,8 @@ class Init {
|
|
|
153
153
|
await ADDS.run('post', {
|
|
154
154
|
config,
|
|
155
155
|
options,
|
|
156
|
-
manifest
|
|
156
|
+
manifest,
|
|
157
|
+
master: Init
|
|
157
158
|
});
|
|
158
159
|
log.info('Application initalization finished');
|
|
159
160
|
} catch (e) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -11,7 +11,7 @@ const initNotApp = require('./app');
|
|
|
11
11
|
const initSessions = require('./sessions');
|
|
12
12
|
const initTemplate = require('./template');
|
|
13
13
|
const initCORS = require('./cors');
|
|
14
|
-
const initCore = require('./core');
|
|
14
|
+
//const initCore = require('./core');
|
|
15
15
|
const initMiddleware = require('./middleware');
|
|
16
16
|
const initStatic = require('./static');
|
|
17
17
|
const initRoutes = require('./routes');
|
|
@@ -25,8 +25,6 @@ module.exports = [
|
|
|
25
25
|
//creating set of variables derived from basic ones,
|
|
26
26
|
//such as various paths, server names and URIs
|
|
27
27
|
initEnv,
|
|
28
|
-
//init various resources like common object fields descriptions and locales
|
|
29
|
-
initCore,
|
|
30
28
|
//DB access drivers
|
|
31
29
|
initDB,
|
|
32
30
|
//http(s) server
|
|
@@ -41,6 +39,8 @@ module.exports = [
|
|
|
41
39
|
initMethodOverride,
|
|
42
40
|
//not-node core
|
|
43
41
|
initNotApp,
|
|
42
|
+
//init various resources like common object fields descriptions and locales
|
|
43
|
+
//initCore,
|
|
44
44
|
//user sessions
|
|
45
45
|
initSessions,
|
|
46
46
|
//template engine
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search and register notModule resouces
|
|
3
|
+
* @class
|
|
4
|
+
**/
|
|
5
|
+
module.exports = class BatchRunner{
|
|
6
|
+
#processors = [];
|
|
7
|
+
constructor(processors){
|
|
8
|
+
this.setProcessors(processors);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setProcessors(list = []){
|
|
12
|
+
this.#processors = [...list];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
resetProcessors(){
|
|
16
|
+
this.setProcessors();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Searching for content of module and registering it.
|
|
21
|
+
* @static
|
|
22
|
+
* @param {Object} input
|
|
23
|
+
* @param {notModule} input.nModule
|
|
24
|
+
* @return {boolean} true - executed, false - no paths
|
|
25
|
+
**/
|
|
26
|
+
exec({nModule}) {
|
|
27
|
+
if (!nModule.module.paths) {return false;}
|
|
28
|
+
//starting from simpliest forms and moving upwards
|
|
29
|
+
this.#processors.forEach(processor => new processor({nModule}));
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const {notError} = require('not-error');
|
|
2
|
+
const {log, error} = require('not-log')(module, 'initializator');
|
|
3
|
+
|
|
4
|
+
module.exports = class notModuleInitializatorForms{
|
|
5
|
+
|
|
6
|
+
static openFile = require;
|
|
7
|
+
|
|
8
|
+
constructor({nModule}){
|
|
9
|
+
this.run({nModule, app: nModule.getApp()});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
run({app, nModule}){
|
|
13
|
+
const moduleName = nModule.getName();
|
|
14
|
+
for (let formName in nModule.getFormsConstructors()) {
|
|
15
|
+
try{
|
|
16
|
+
const formConstructor = nModule.getFormConstructor(formName);
|
|
17
|
+
nModule.setForm(formName, new formConstructor({app}));
|
|
18
|
+
//log(`${moduleName}//${formName}`);
|
|
19
|
+
}catch(e){
|
|
20
|
+
error(`Error while initialization of form: ${moduleName}//${formName}`);
|
|
21
|
+
if(e instanceof notError){
|
|
22
|
+
error(`name: ${e.options.field}, type: ${e.options.type}`);
|
|
23
|
+
}else{
|
|
24
|
+
error(e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const BatchRunner = require('../batchRunner.js');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Logic to find and register resources of notModule
|
|
5
|
+
* @module notModuleRegistrator
|
|
6
|
+
**/
|
|
7
|
+
|
|
8
|
+
const
|
|
9
|
+
notModuleInitializatorForms = require('./forms'),
|
|
10
|
+
notModuleInitializatorModels = require('./models'),
|
|
11
|
+
notModuleInitializatorManifests = require('./manifests');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const DEFAULT_INITIALIZATORS = [
|
|
15
|
+
notModuleInitializatorForms,
|
|
16
|
+
notModuleInitializatorModels,
|
|
17
|
+
notModuleInitializatorManifests
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Initialize registered notModule resouces
|
|
22
|
+
* @class
|
|
23
|
+
**/
|
|
24
|
+
module.exports = new BatchRunner(DEFAULT_INITIALIZATORS);
|