not-node 5.0.18 → 5.0.22
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/error.format +11 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/src/bootstrap/form.js +18 -0
- package/src/bootstrap/index.js +11 -0
- package/src/bootstrap/logic.js +46 -0
- package/src/bootstrap/model.js +18 -0
- package/src/bootstrap/route.js +60 -0
- package/src/core/locales/en.json +2 -0
- package/src/core/locales/ru.json +2 -0
- package/src/fields/index.js +85 -62
- package/src/generic/router.js +16 -0
- package/src/getApp.js +2 -0
- package/src/model/versioning.js +7 -1
package/error.format
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
server returns errors with http codes
|
|
2
|
+
and additional info in form of JSON
|
|
3
|
+
{
|
|
4
|
+
status: 'error', //<- main marker
|
|
5
|
+
message: 'short description', //<- could be empty if server is dont want to disclose any information on cause
|
|
6
|
+
//optional
|
|
7
|
+
errors: {
|
|
8
|
+
field_name: ['error1'],
|
|
9
|
+
field_name2: ['err','fake']
|
|
10
|
+
}
|
|
11
|
+
}
|
package/index.js
CHANGED
|
@@ -37,3 +37,5 @@ module.exports.FormFabric = require('./src/form').FormFabric;
|
|
|
37
37
|
module.exports.Init = require('./src/init').Init;
|
|
38
38
|
/** Application object */
|
|
39
39
|
module.exports.Application = null;
|
|
40
|
+
/** Application bootstrap helpers */
|
|
41
|
+
module.exports.Bootstrap = require('./src/bootstrap');
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { getIP } = require("../auth"),
|
|
2
|
+
configInit = require("not-config"),
|
|
3
|
+
{ sayForModule } = require("not-locale"),
|
|
4
|
+
LogInit = require("not-log");
|
|
5
|
+
|
|
6
|
+
module.exports = ({ target, MODULE_NAME, MODEL_NAME, ACTION_NAME }) => {
|
|
7
|
+
const Log = LogInit(target, `${MODEL_NAME}/Forms'`);
|
|
8
|
+
const say = sayForModule(MODULE_NAME);
|
|
9
|
+
|
|
10
|
+
const config = configInit.readerForModule(MODULE_NAME);
|
|
11
|
+
return {
|
|
12
|
+
getIP,
|
|
13
|
+
FORM_NAME: `${MODULE_NAME}:${ACTION_NAME}Form`,
|
|
14
|
+
Log,
|
|
15
|
+
say,
|
|
16
|
+
config,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const notBootstrapLogic = require("./logic");
|
|
2
|
+
const notBootstrapForm = require("./form");
|
|
3
|
+
const notBootstrapRoute = require("./route");
|
|
4
|
+
const notBootstrapModel = require("./model");
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
notBootstrapLogic,
|
|
8
|
+
notBootstrapForm,
|
|
9
|
+
notBootstrapRoute,
|
|
10
|
+
notBootstrapModel,
|
|
11
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const getApp = require("../getApp.js"),
|
|
2
|
+
configInit = require("not-config"),
|
|
3
|
+
{sayForModule, modulePhrase} = require('not-locale'),
|
|
4
|
+
LogInit = require("not-log");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module.exports = ({target, MODULE_NAME, MODEL_NAME, USER_MODEL_NAME = 'not-user//User'})=>{
|
|
8
|
+
|
|
9
|
+
const Log = LogInit(target, `${MODULE_NAME}/Logic/${MODEL_NAME}`);
|
|
10
|
+
const say = sayForModule(MODULE_NAME);
|
|
11
|
+
const phrase = modulePhrase(MODULE_NAME);
|
|
12
|
+
const config = configInit.readerForModule(MODULE_NAME);
|
|
13
|
+
|
|
14
|
+
const LogAction = ({action, by, role, ip}, params = {})=>{
|
|
15
|
+
Log.log({
|
|
16
|
+
time: new Date(),
|
|
17
|
+
module: MODULE_NAME,
|
|
18
|
+
logic: MODEL_NAME,
|
|
19
|
+
action,
|
|
20
|
+
by,
|
|
21
|
+
role,
|
|
22
|
+
ip,
|
|
23
|
+
params
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
Log,
|
|
29
|
+
LogAction,
|
|
30
|
+
say,
|
|
31
|
+
phrase,
|
|
32
|
+
config,
|
|
33
|
+
getModel(){
|
|
34
|
+
return getApp().getModel(`${MODULE_NAME}//${MODEL_NAME}`);
|
|
35
|
+
},
|
|
36
|
+
getModelSchema(){
|
|
37
|
+
return getApp().getModelSchema(`${MODULE_NAME}//${MODEL_NAME}`);
|
|
38
|
+
},
|
|
39
|
+
getLogic(){
|
|
40
|
+
return getApp().getLogic(`${MODULE_NAME}//${MODEL_NAME}`);
|
|
41
|
+
},
|
|
42
|
+
getModelUser(){
|
|
43
|
+
return getApp().getModel(USER_MODEL_NAME);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const
|
|
2
|
+
configInit = require("not-config"),
|
|
3
|
+
{ sayForModule } = require("not-locale"),
|
|
4
|
+
|
|
5
|
+
LogInit = require("not-log");
|
|
6
|
+
|
|
7
|
+
module.exports = ({ target, MODULE_NAME, MODEL_NAME}) => {
|
|
8
|
+
const Log = LogInit(target, `${MODEL_NAME}/Models'`);
|
|
9
|
+
const say = sayForModule(MODULE_NAME);
|
|
10
|
+
|
|
11
|
+
const config = configInit.readerForModule(MODULE_NAME);
|
|
12
|
+
return {
|
|
13
|
+
Log,
|
|
14
|
+
say,
|
|
15
|
+
config
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const getApp = require("../getApp.js"),
|
|
2
|
+
configInit = require("not-config"),
|
|
3
|
+
{ sayForModule } = require("not-locale"),
|
|
4
|
+
{ objHas } = require("../common"),
|
|
5
|
+
LogInit = require("not-log");
|
|
6
|
+
|
|
7
|
+
module.exports = ({ target, MODULE_NAME, MODEL_NAME, USER_MODEL_NAME = 'not-user//User' }) => {
|
|
8
|
+
const Log = LogInit(target, `${MODEL_NAME}/Routes'`);
|
|
9
|
+
const say = sayForModule(MODULE_NAME);
|
|
10
|
+
|
|
11
|
+
const beforeDecorator = async (req, res, next) => {
|
|
12
|
+
const name = req.notRouteData.actionName;
|
|
13
|
+
const FormValidator = getApp().getForm(
|
|
14
|
+
[MODULE_NAME, name.replace("_", "")].join("//")
|
|
15
|
+
);
|
|
16
|
+
if (FormValidator) {
|
|
17
|
+
return await FormValidator.run(req, res, next);
|
|
18
|
+
} else {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const afterDecorator = (req, res, next, result) => {
|
|
24
|
+
const name = req.notRouteData.actionName;
|
|
25
|
+
if (res.headersSent) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (result && objHas(result, "__redirect__")) {
|
|
29
|
+
res.status(200).redirect(result.__redirect__);
|
|
30
|
+
} else {
|
|
31
|
+
res.status(200).json({
|
|
32
|
+
status: "ok",
|
|
33
|
+
message: say(`action_message_${name}_success`, {}, res.locals.locale),
|
|
34
|
+
result,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const config = configInit.readerForModule(MODULE_NAME);
|
|
40
|
+
return {
|
|
41
|
+
before: beforeDecorator,
|
|
42
|
+
after: afterDecorator,
|
|
43
|
+
Log,
|
|
44
|
+
say,
|
|
45
|
+
config,
|
|
46
|
+
getModel() {
|
|
47
|
+
return getApp().getModel(`${MODULE_NAME}//${MODEL_NAME}`);
|
|
48
|
+
},
|
|
49
|
+
getModelSchema() {
|
|
50
|
+
return getApp().getModelSchema(`${MODULE_NAME}//${MODEL_NAME}`);
|
|
51
|
+
},
|
|
52
|
+
getLogic() {
|
|
53
|
+
return getApp().getLogic(`${MODULE_NAME}//${MODEL_NAME}`);
|
|
54
|
+
},
|
|
55
|
+
getModelUser(){
|
|
56
|
+
return getApp().getModel(USER_MODEL_NAME);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
};
|
package/src/core/locales/en.json
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
"button_cancel_label": "Cancel",
|
|
8
8
|
"button_apply_label": "Apply",
|
|
9
9
|
"field_select_label": "Select",
|
|
10
|
+
"field_value_is_empty_placeholder": "Empty",
|
|
11
|
+
"loading_label": "Loading...",
|
|
10
12
|
"field_search_placeholder": "Search...",
|
|
11
13
|
"field_owner_label": "Owner",
|
|
12
14
|
"form_validation_error": "Form validation error",
|
package/src/core/locales/ru.json
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
"field_select_label": "Выбрать",
|
|
8
8
|
"field_search_placeholder": "Искать...",
|
|
9
9
|
"field_owner_label": "Владелец",
|
|
10
|
+
"field_value_is_empty_placeholder": "Пусто",
|
|
11
|
+
"loading_label": "Загрузка...",
|
|
10
12
|
"button_cancel_label": "Отмена",
|
|
11
13
|
"button_apply_label": "Применить",
|
|
12
14
|
"form_validation_error": "Форма заполнена с ошибками",
|
package/src/fields/index.js
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
const clone = require(
|
|
2
|
-
const notPath = require(
|
|
3
|
-
const {error} = require(
|
|
4
|
-
const {notError} = require('not-error');
|
|
1
|
+
const clone = require("rfdc")();
|
|
2
|
+
const notPath = require("not-path");
|
|
3
|
+
const { error } = require("not-log")(module, "init//fields");
|
|
5
4
|
|
|
6
|
-
const {
|
|
7
|
-
objHas,
|
|
8
|
-
} = require('../common');
|
|
5
|
+
const { objHas } = require("../common");
|
|
9
6
|
|
|
10
|
-
const DEFAULT_TYPE =
|
|
11
|
-
const DEFAULT_FROM =
|
|
12
|
-
const DEFAULT_TO =
|
|
7
|
+
const DEFAULT_TYPE = "ui";
|
|
8
|
+
const DEFAULT_FROM = ":FIELDS";
|
|
9
|
+
const DEFAULT_TO = ":thisSchema";
|
|
13
10
|
|
|
14
|
-
module.exports.initFileSchemaFromFields = ({
|
|
11
|
+
module.exports.initFileSchemaFromFields = ({
|
|
12
|
+
app,
|
|
13
|
+
mod,
|
|
14
|
+
type = DEFAULT_TYPE,
|
|
15
|
+
from = DEFAULT_FROM,
|
|
16
|
+
to = DEFAULT_TO,
|
|
17
|
+
moduleName = "",
|
|
18
|
+
}) => {
|
|
15
19
|
const FIELDS = notPath.get(from, mod);
|
|
16
|
-
if(FIELDS && Array.isArray(FIELDS)){
|
|
17
|
-
const schema = module.exports.createSchemaFromFields(
|
|
20
|
+
if (FIELDS && Array.isArray(FIELDS)) {
|
|
21
|
+
const schema = module.exports.createSchemaFromFields(
|
|
22
|
+
app,
|
|
23
|
+
FIELDS,
|
|
24
|
+
type,
|
|
25
|
+
moduleName
|
|
26
|
+
);
|
|
18
27
|
notPath.set(to, mod, schema);
|
|
19
28
|
}
|
|
20
29
|
};
|
|
@@ -26,26 +35,40 @@ fields = [
|
|
|
26
35
|
['someID', {}, 'ID'], //copy of standart ID field under name as someID
|
|
27
36
|
]
|
|
28
37
|
**/
|
|
29
|
-
module.exports.createSchemaFromFields = (
|
|
38
|
+
module.exports.createSchemaFromFields = (
|
|
39
|
+
app,
|
|
40
|
+
fields,
|
|
41
|
+
type = "ui",
|
|
42
|
+
moduleName
|
|
43
|
+
) => {
|
|
30
44
|
let schema = {};
|
|
31
45
|
fields.forEach((field) => {
|
|
32
|
-
let [schemaFieldName, schemaFieldValue] = module.exports.initSchemaField(
|
|
46
|
+
let [schemaFieldName, schemaFieldValue] = module.exports.initSchemaField(
|
|
47
|
+
app,
|
|
48
|
+
field,
|
|
49
|
+
false,
|
|
50
|
+
type,
|
|
51
|
+
moduleName
|
|
52
|
+
);
|
|
33
53
|
schema[schemaFieldName] = schemaFieldValue;
|
|
34
54
|
});
|
|
35
55
|
return schema;
|
|
36
56
|
};
|
|
37
57
|
|
|
38
|
-
|
|
39
|
-
|
|
58
|
+
module.exports.initSchemaField = (
|
|
59
|
+
app,
|
|
60
|
+
field,
|
|
61
|
+
resultOnly = true,
|
|
62
|
+
type = "ui",
|
|
63
|
+
moduleName
|
|
64
|
+
) => {
|
|
40
65
|
//log(field);
|
|
41
|
-
let {
|
|
42
|
-
srcName,
|
|
43
|
-
destName,
|
|
44
|
-
mutation
|
|
45
|
-
} = parseFieldDescription(field);
|
|
66
|
+
let { srcName, destName, mutation } = parseFieldDescription(field);
|
|
46
67
|
let proto = findFieldPrototype(app, srcName, type);
|
|
47
|
-
if(!proto){
|
|
48
|
-
error(
|
|
68
|
+
if (!proto) {
|
|
69
|
+
error(
|
|
70
|
+
`field ${moduleName}//${destName} prototype ${srcName} of ${type} type is not found`
|
|
71
|
+
);
|
|
49
72
|
}
|
|
50
73
|
let schemaFieldValue = Object.assign({}, clone(proto), mutation);
|
|
51
74
|
if (resultOnly) {
|
|
@@ -56,25 +79,26 @@ module.exports.initSchemaField = (app, field, resultOnly = true, type = 'ui', mo
|
|
|
56
79
|
};
|
|
57
80
|
|
|
58
81
|
/**
|
|
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
|
|
64
|
-
**/
|
|
82
|
+
* field form
|
|
83
|
+
* 'destFieldNameSameAsSourceFieldName' - form 1
|
|
84
|
+
* ['destFieldName', {full: true, field: 'content'}] - form 2
|
|
85
|
+
* ['destFieldName', 'srcFieldName'] //field alias, form 3
|
|
86
|
+
* ['destFieldName', {mutation: 'content'}, 'srcFieldName']// - form 4
|
|
87
|
+
**/
|
|
65
88
|
const parseFieldDescription = (field) => {
|
|
66
89
|
let srcName,
|
|
67
90
|
destName,
|
|
68
91
|
mutation = {};
|
|
69
92
|
if (Array.isArray(field)) {
|
|
70
93
|
destName = srcName = field[0];
|
|
71
|
-
if(field.length === 2){
|
|
72
|
-
if(typeof field[1] ===
|
|
94
|
+
if (field.length === 2) {
|
|
95
|
+
if (typeof field[1] === "string") {
|
|
73
96
|
srcName = field[1]; //form 3
|
|
74
|
-
}else{
|
|
97
|
+
} else {
|
|
75
98
|
mutation = field[1]; //form 2
|
|
76
99
|
}
|
|
77
|
-
}else if (field.length === 3) {
|
|
100
|
+
} else if (field.length === 3) {
|
|
101
|
+
//form 4
|
|
78
102
|
mutation = field[1];
|
|
79
103
|
srcName = field[2];
|
|
80
104
|
}
|
|
@@ -84,39 +108,38 @@ const parseFieldDescription = (field) => {
|
|
|
84
108
|
return {
|
|
85
109
|
srcName,
|
|
86
110
|
destName,
|
|
87
|
-
mutation
|
|
111
|
+
mutation,
|
|
88
112
|
};
|
|
89
113
|
};
|
|
90
114
|
|
|
91
115
|
const findFieldPrototype = (app, name, type) => {
|
|
92
116
|
const fieldPrototype = app.getField(name);
|
|
93
|
-
if(fieldPrototype && objHas(fieldPrototype, type)){
|
|
117
|
+
if (fieldPrototype && objHas(fieldPrototype, type)) {
|
|
94
118
|
return fieldPrototype[type];
|
|
95
|
-
}else{
|
|
119
|
+
} else {
|
|
96
120
|
return null;
|
|
97
121
|
}
|
|
98
122
|
};
|
|
99
123
|
|
|
100
124
|
/**
|
|
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
|
|
109
|
-
**/
|
|
125
|
+
* Creates fields UI representation schema from list of fields in DB model
|
|
126
|
+
* and library of fields
|
|
127
|
+
* @param {object} app notApplication instance
|
|
128
|
+
* @param {object} schema model db schema
|
|
129
|
+
* @param {Array<string|Array>} rawMutationsList fields mutations, for little tuning
|
|
130
|
+
* @param {Array<string>} privateFields fields to omit from result
|
|
131
|
+
* @param {string} moduleName for detailed reports on issues, in which module and what field is faulty
|
|
132
|
+
* @returns {object} resulting UI rendering schema for fields
|
|
133
|
+
**/
|
|
110
134
|
|
|
111
135
|
module.exports.initManifestFields = (
|
|
112
|
-
app,
|
|
113
|
-
schema,
|
|
114
|
-
rawMutationsList = [],
|
|
115
|
-
privateFields = [],
|
|
116
|
-
moduleName
|
|
136
|
+
app, //notApplication
|
|
137
|
+
schema, //schema of model
|
|
138
|
+
rawMutationsList = [], //fields mutations
|
|
139
|
+
privateFields = [], //fields to omit
|
|
140
|
+
moduleName //module name for reporting
|
|
117
141
|
) => {
|
|
118
|
-
let
|
|
119
|
-
//shallow copy of array
|
|
142
|
+
let //shallow copy of array
|
|
120
143
|
mutationsList = [...rawMutationsList],
|
|
121
144
|
list = [];
|
|
122
145
|
if (schema && Object.keys(schema).length > 0) {
|
|
@@ -133,20 +156,20 @@ module.exports.initManifestFields = (
|
|
|
133
156
|
}
|
|
134
157
|
});
|
|
135
158
|
list.push(...mutationsList);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return {};
|
|
159
|
+
} else {
|
|
160
|
+
list = mutationsList;
|
|
139
161
|
}
|
|
162
|
+
return module.exports.createSchemaFromFields(app, list, "ui", moduleName);
|
|
140
163
|
};
|
|
141
164
|
|
|
142
165
|
/**
|
|
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
|
-
*/
|
|
166
|
+
* Returns mutation tuple for a field or false
|
|
167
|
+
* @param {string} name field name
|
|
168
|
+
* @param {Array} list fields description lists
|
|
169
|
+
* @return {boolean|item}
|
|
170
|
+
*/
|
|
148
171
|
function getMutationForField(name, list) {
|
|
149
|
-
for(let item of list){
|
|
172
|
+
for (let item of list) {
|
|
150
173
|
if (Array.isArray(item) && item[0] === name) {
|
|
151
174
|
return item;
|
|
152
175
|
}
|
package/src/getApp.js
ADDED
package/src/model/versioning.js
CHANGED
|
@@ -36,10 +36,16 @@ class ModelVersioning{
|
|
|
36
36
|
return a;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
static jsonCopy(a){
|
|
40
|
+
return JSON.parse(JSON.stringify(a));
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
static isThisDocsDifferent(a, b) {
|
|
40
44
|
a = ModelVersioning.stripTechData(a);
|
|
41
45
|
b = ModelVersioning.stripTechData(b);
|
|
42
|
-
|
|
46
|
+
const plainA = ModelVersioning.jsonCopy(a);
|
|
47
|
+
const plainB = ModelVersioning.jsonCopy(b);
|
|
48
|
+
const diffLog = diff(plainA, plainB);
|
|
43
49
|
return (typeof diffLog !== 'undefined');
|
|
44
50
|
}
|
|
45
51
|
|