not-node 4.0.17 → 4.0.21
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/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
2
3
|
const notPath = require('not-path');
|
|
3
4
|
|
|
4
5
|
/** @module Common */
|
|
@@ -8,7 +9,7 @@ const notPath = require('not-path');
|
|
|
8
9
|
* @return {string} result
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
module.exports.firstLetterToLower = function
|
|
12
|
+
module.exports.firstLetterToLower = function(string) {
|
|
12
13
|
return string.charAt(0).toLowerCase() + string.slice(1);
|
|
13
14
|
};
|
|
14
15
|
|
|
@@ -18,7 +19,7 @@ module.exports.firstLetterToLower = function (string) {
|
|
|
18
19
|
* @return {string} result
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
|
-
module.exports.firstLetterToUpper = function
|
|
22
|
+
module.exports.firstLetterToUpper = function(string) {
|
|
22
23
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
23
24
|
};
|
|
24
25
|
|
|
@@ -27,10 +28,10 @@ module.exports.firstLetterToUpper = function (string) {
|
|
|
27
28
|
* @param {string} id ObjectId string to validate
|
|
28
29
|
* @return {booelean} true if check is not failed
|
|
29
30
|
*/
|
|
30
|
-
module.exports.validateObjectId = (id)=>{
|
|
31
|
-
try{
|
|
32
|
-
return id.match(/^[0-9a-fA-F]{24}$/)?true:false;
|
|
33
|
-
}catch(e){
|
|
31
|
+
module.exports.validateObjectId = (id) => {
|
|
32
|
+
try {
|
|
33
|
+
return id.match(/^[0-9a-fA-F]{24}$/) ? true : false;
|
|
34
|
+
} catch (e) {
|
|
34
35
|
return false;
|
|
35
36
|
}
|
|
36
37
|
};
|
|
@@ -41,24 +42,24 @@ module.exports.validateObjectId = (id)=>{
|
|
|
41
42
|
* @param {string|ObjectId} secondId second id
|
|
42
43
|
* @return {booelean} true if equal
|
|
43
44
|
*/
|
|
44
|
-
module.exports.compareObjectIds = (firstId, secondId)=>{
|
|
45
|
-
try{
|
|
46
|
-
let a = firstId,
|
|
47
|
-
|
|
45
|
+
module.exports.compareObjectIds = (firstId, secondId) => {
|
|
46
|
+
try {
|
|
47
|
+
let a = firstId,
|
|
48
|
+
b = secondId;
|
|
49
|
+
if (typeof firstId !== 'string') {
|
|
48
50
|
a = a.toString();
|
|
49
51
|
}
|
|
50
|
-
if(typeof secondId !== 'string'){
|
|
52
|
+
if (typeof secondId !== 'string') {
|
|
51
53
|
b = b.toString();
|
|
52
54
|
}
|
|
53
|
-
if(
|
|
54
|
-
!module.exports.validateObjectId(a)
|
|
55
|
-
||
|
|
55
|
+
if (
|
|
56
|
+
!module.exports.validateObjectId(a) ||
|
|
56
57
|
!module.exports.validateObjectId(b)
|
|
57
|
-
){
|
|
58
|
+
) {
|
|
58
59
|
return false;
|
|
59
60
|
}
|
|
60
61
|
return a === b;
|
|
61
|
-
}catch(e){
|
|
62
|
+
} catch (e) {
|
|
62
63
|
return false;
|
|
63
64
|
}
|
|
64
65
|
};
|
|
@@ -67,9 +68,9 @@ module.exports.compareObjectIds = (firstId, secondId)=>{
|
|
|
67
68
|
* Returns today Date object without hours, minutes, seconds
|
|
68
69
|
* @return {number} current date with 00:00:00 in ms of unix time
|
|
69
70
|
*/
|
|
70
|
-
module.exports.getTodayDate = ()=>{
|
|
71
|
+
module.exports.getTodayDate = () => {
|
|
71
72
|
let t = new Date();
|
|
72
|
-
return (new Date(t.getFullYear(), t.getMonth(),t.getDate())).getTime();
|
|
73
|
+
return (new Date(t.getFullYear(), t.getMonth(), t.getDate())).getTime();
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
|
|
@@ -84,22 +85,22 @@ module.exports.objHas = objHas;
|
|
|
84
85
|
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
|
-
* Copies object to secure it from changes
|
|
88
|
-
* @param {object} obj original object
|
|
89
|
-
* @return {object} copy of object
|
|
90
|
-
**/
|
|
88
|
+
* Copies object to secure it from changes
|
|
89
|
+
* @param {object} obj original object
|
|
90
|
+
* @return {object} copy of object
|
|
91
|
+
**/
|
|
91
92
|
module.exports.copyObj = (obj) => {
|
|
92
93
|
return JSON.parse(JSON.stringify(obj));
|
|
93
94
|
};
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
|
-
* Copies object to secure it from changes
|
|
97
|
-
* @param {object} obj original object
|
|
98
|
-
* @return {object} copy of object
|
|
99
|
-
**/
|
|
97
|
+
* Copies object to secure it from changes
|
|
98
|
+
* @param {object} obj original object
|
|
99
|
+
* @return {object} copy of object
|
|
100
|
+
**/
|
|
100
101
|
module.exports.partCopyObj = (obj, list) => {
|
|
101
|
-
let partObj =
|
|
102
|
-
if(list.includes(curr)){
|
|
102
|
+
let partObj = Object.keys(obj).reduce((prev, curr) => {
|
|
103
|
+
if (list.includes(curr)) {
|
|
103
104
|
prev[curr] = obj[curr];
|
|
104
105
|
}
|
|
105
106
|
return prev;
|
|
@@ -109,38 +110,38 @@ module.exports.partCopyObj = (obj, list) => {
|
|
|
109
110
|
|
|
110
111
|
|
|
111
112
|
/**
|
|
112
|
-
* Test argument type to be 'function'
|
|
113
|
-
* @param {any} func possible function
|
|
114
|
-
* @return {boolean} if this is a function
|
|
115
|
-
**/
|
|
113
|
+
* Test argument type to be 'function'
|
|
114
|
+
* @param {any} func possible function
|
|
115
|
+
* @return {boolean} if this is a function
|
|
116
|
+
**/
|
|
116
117
|
const isFunc = module.exports.isFunc = (func) => {
|
|
117
118
|
return typeof func === 'function';
|
|
118
119
|
};
|
|
119
120
|
|
|
120
121
|
/**
|
|
121
|
-
* Returns true if argument is Async function
|
|
122
|
-
* @param {function} func to test
|
|
123
|
-
* @return {boolean} if this function is constructed as AsyncFunction
|
|
124
|
-
**/
|
|
122
|
+
* Returns true if argument is Async function
|
|
123
|
+
* @param {function} func to test
|
|
124
|
+
* @return {boolean} if this function is constructed as AsyncFunction
|
|
125
|
+
**/
|
|
125
126
|
const isAsync = module.exports.isAsync = (func) => {
|
|
126
127
|
return func.constructor.name === 'AsyncFunction';
|
|
127
128
|
};
|
|
128
129
|
|
|
129
130
|
|
|
130
131
|
/**
|
|
131
|
-
* Executes method of object in appropriate way inside Promise
|
|
132
|
-
* @param {object} obj original object
|
|
133
|
-
* @param {string} name method name to execute
|
|
134
|
-
* @param {Array} params array of params
|
|
135
|
-
* @return {Promise} results of method execution
|
|
136
|
-
**/
|
|
132
|
+
* Executes method of object in appropriate way inside Promise
|
|
133
|
+
* @param {object} obj original object
|
|
134
|
+
* @param {string} name method name to execute
|
|
135
|
+
* @param {Array} params array of params
|
|
136
|
+
* @return {Promise} results of method execution
|
|
137
|
+
**/
|
|
137
138
|
module.exports.executeObjectFunction = async (obj, name, params) => {
|
|
138
|
-
if (obj){
|
|
139
|
+
if (obj) {
|
|
139
140
|
const proc = notPath.get(':' + name, obj);
|
|
140
|
-
if(isFunc(proc)){
|
|
141
|
-
if(isAsync(proc)){
|
|
141
|
+
if (isFunc(proc)) {
|
|
142
|
+
if (isAsync(proc)) {
|
|
142
143
|
return await proc(...params);
|
|
143
|
-
}else{
|
|
144
|
+
} else {
|
|
144
145
|
return proc(...params);
|
|
145
146
|
}
|
|
146
147
|
}
|
|
@@ -149,14 +150,14 @@ module.exports.executeObjectFunction = async (obj, name, params) => {
|
|
|
149
150
|
|
|
150
151
|
|
|
151
152
|
/**
|
|
152
|
-
* Executes method of object in apropriate way inside Promise
|
|
153
|
-
* @param {Object} from original object
|
|
154
|
-
* @param {Object} name method name to execute
|
|
155
|
-
* @param {Array} list array of params
|
|
156
|
-
* @return {Promise} results of method execution
|
|
157
|
-
**/
|
|
153
|
+
* Executes method of object in apropriate way inside Promise
|
|
154
|
+
* @param {Object} from original object
|
|
155
|
+
* @param {Object} name method name to execute
|
|
156
|
+
* @param {Array} list array of params
|
|
157
|
+
* @return {Promise} results of method execution
|
|
158
|
+
**/
|
|
158
159
|
module.exports.mapBind = (from, to, list) => {
|
|
159
|
-
list.forEach((item)=>{
|
|
160
|
+
list.forEach((item) => {
|
|
160
161
|
if (typeof from[item] === 'function') {
|
|
161
162
|
to[item] = from[item].bind(from);
|
|
162
163
|
}
|
|
@@ -165,10 +166,10 @@ module.exports.mapBind = (from, to, list) => {
|
|
|
165
166
|
|
|
166
167
|
|
|
167
168
|
/**
|
|
168
|
-
* Synchronously check file existence and if it's really a file
|
|
169
|
-
* @param {string} filePath full path to file
|
|
170
|
-
* @return {boolean} true if path exists and it's a file
|
|
171
|
-
**/
|
|
169
|
+
* Synchronously check file existence and if it's really a file
|
|
170
|
+
* @param {string} filePath full path to file
|
|
171
|
+
* @return {boolean} true if path exists and it's a file
|
|
172
|
+
**/
|
|
172
173
|
module.exports.tryFile = (filePath) => {
|
|
173
174
|
try {
|
|
174
175
|
const stat = fs.lstatSync(filePath);
|
|
@@ -177,3 +178,18 @@ module.exports.tryFile = (filePath) => {
|
|
|
177
178
|
return false;
|
|
178
179
|
}
|
|
179
180
|
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Generates paths object for module/index.js files based on content and relative
|
|
184
|
+
* path
|
|
185
|
+
* @param {Array<string>} content list of module components ['models', 'logics', 'routes',...]
|
|
186
|
+
* @param {string} relative path to parent folder of components
|
|
187
|
+
* @param {Object} paths object for module/index.js
|
|
188
|
+
**/
|
|
189
|
+
module.exports.generatePaths = (content = [], relative = 'src') => {
|
|
190
|
+
const toPath = (name) => path.join(relative, name);
|
|
191
|
+
return content.reduce((prev, cur) => {
|
|
192
|
+
prev[cur] = toPath(cur);
|
|
193
|
+
return prev;
|
|
194
|
+
}, {});
|
|
195
|
+
};
|
package/src/core/fields/owner.js
CHANGED
|
@@ -36,14 +36,30 @@ module.exports = class notModuleRegistratorFields{
|
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
registerField({name, field, fieldsImportRules}){
|
|
39
|
+
registerField({name, field, fieldsImportRules, fromPath}){
|
|
40
|
+
this.extendByFrontValidators({name, field, fromPath});
|
|
40
41
|
notModuleRegistratorFields.fieldsManager.registerField(
|
|
41
|
-
name,
|
|
42
|
-
field,
|
|
42
|
+
name, //field name
|
|
43
|
+
field, //field description
|
|
43
44
|
fieldsImportRules //global import rules
|
|
44
45
|
);
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
**/
|
|
51
|
+
extendByFrontValidators({name, field, fromPath}){
|
|
52
|
+
if(!(field && objHas(field, 'model'))){ return; }
|
|
53
|
+
//load validators
|
|
54
|
+
const validatorName = path.join(fromPath, 'validators', name + '.js');
|
|
55
|
+
if(!tryFile(validatorName)){return;}
|
|
56
|
+
const validators = notModuleRegistratorFields.openFile(validatorName);
|
|
57
|
+
//inject into field.model
|
|
58
|
+
if(!objHas(field.model, 'validate')){
|
|
59
|
+
field.model.validate = [];
|
|
60
|
+
}
|
|
61
|
+
field.model.validate.push(...validators);
|
|
62
|
+
}
|
|
47
63
|
|
|
48
64
|
|
|
49
65
|
/**
|
|
@@ -72,11 +88,10 @@ module.exports = class notModuleRegistratorFields{
|
|
|
72
88
|
this.registerField({
|
|
73
89
|
name: parts.name, //fields name
|
|
74
90
|
field: fields, //field description
|
|
75
|
-
fieldsImportRules: nModule.fieldsImportRules //global import rules
|
|
91
|
+
fieldsImportRules: nModule.fieldsImportRules, //global import rules
|
|
92
|
+
fromPath
|
|
76
93
|
});
|
|
77
94
|
}
|
|
78
95
|
}
|
|
79
96
|
|
|
80
|
-
|
|
81
|
-
|
|
82
97
|
};
|
|
@@ -12,7 +12,11 @@ function extractValidationEnvGetter(options){
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function extendObsolete(rule){
|
|
15
|
-
|
|
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);
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
function extendModern(rule, options){
|
package/test/module/fields.js
CHANGED
|
@@ -24,7 +24,8 @@ module.exports = ({
|
|
|
24
24
|
describe('run', function() {
|
|
25
25
|
it('path to fields is not defined', function() {
|
|
26
26
|
const ctx = {
|
|
27
|
-
findAll() {}
|
|
27
|
+
findAll() {},
|
|
28
|
+
extendByFrontValidators(){}
|
|
28
29
|
};
|
|
29
30
|
const param = {
|
|
30
31
|
nModule: {
|
|
@@ -39,7 +40,8 @@ module.exports = ({
|
|
|
39
40
|
|
|
40
41
|
it('paths to fields is defined', function() {
|
|
41
42
|
const ctx = {
|
|
42
|
-
findAll() {}
|
|
43
|
+
findAll() {},
|
|
44
|
+
extendByFrontValidators(){}
|
|
43
45
|
};
|
|
44
46
|
const param = {
|
|
45
47
|
nModule: {
|
|
@@ -149,7 +151,9 @@ module.exports = ({
|
|
|
149
151
|
|
|
150
152
|
describe('registerField', function() {
|
|
151
153
|
it('file is a single field', () => {
|
|
152
|
-
const ctx = {
|
|
154
|
+
const ctx = {
|
|
155
|
+
extendByFrontValidators(){}
|
|
156
|
+
};
|
|
153
157
|
const param = {
|
|
154
158
|
name: 'single',
|
|
155
159
|
field: require(path.resolve(__dirname, '../testies/module/fields/single.js')),
|