not-node 6.5.31 → 6.5.32
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 +1 -1
- package/src/fields/index.js +90 -36
- package/src/form/form.js +2 -2
- package/src/manifest/initializator/manifests.js +34 -20
- package/src/manifest/module.js +8 -0
package/package.json
CHANGED
package/src/fields/index.js
CHANGED
|
@@ -21,7 +21,7 @@ module.exports.initFileSchemaFromFields = ({
|
|
|
21
21
|
if (FIELDS && Array.isArray(FIELDS)) {
|
|
22
22
|
const schema = module.exports.createSchemaFromFields(
|
|
23
23
|
app,
|
|
24
|
-
FIELDS,
|
|
24
|
+
normalizeFieldsDescriptionsList(FIELDS),
|
|
25
25
|
type,
|
|
26
26
|
moduleName
|
|
27
27
|
);
|
|
@@ -30,11 +30,11 @@ module.exports.initFileSchemaFromFields = ({
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
fields = [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
]
|
|
33
|
+
fields = [{
|
|
34
|
+
srcName:string,
|
|
35
|
+
destName:string,
|
|
36
|
+
mutation:object,
|
|
37
|
+
}]
|
|
38
38
|
**/
|
|
39
39
|
module.exports.createSchemaFromFields = (
|
|
40
40
|
app,
|
|
@@ -43,9 +43,15 @@ module.exports.createSchemaFromFields = (
|
|
|
43
43
|
moduleName
|
|
44
44
|
) => {
|
|
45
45
|
let schema = {};
|
|
46
|
-
fields.forEach((
|
|
46
|
+
fields.forEach((fieldDescription) => {
|
|
47
47
|
let [schemaFieldName, schemaFieldValue] =
|
|
48
|
-
module.exports.initSchemaField(
|
|
48
|
+
module.exports.initSchemaField(
|
|
49
|
+
app,
|
|
50
|
+
fieldDescription,
|
|
51
|
+
false,
|
|
52
|
+
type,
|
|
53
|
+
moduleName
|
|
54
|
+
);
|
|
49
55
|
schema[schemaFieldName] = schemaFieldValue;
|
|
50
56
|
});
|
|
51
57
|
return schema;
|
|
@@ -53,13 +59,13 @@ module.exports.createSchemaFromFields = (
|
|
|
53
59
|
|
|
54
60
|
module.exports.initSchemaField = (
|
|
55
61
|
app,
|
|
56
|
-
|
|
62
|
+
fieldDescription,
|
|
57
63
|
resultOnly = true,
|
|
58
64
|
type = "ui",
|
|
59
65
|
moduleName
|
|
60
66
|
) => {
|
|
61
67
|
//log(field);
|
|
62
|
-
let { srcName, destName, mutation } =
|
|
68
|
+
let { srcName, destName, mutation } = fieldDescription;
|
|
63
69
|
let proto = findFieldPrototype(app, srcName, type);
|
|
64
70
|
if (!proto) {
|
|
65
71
|
error(
|
|
@@ -124,11 +130,24 @@ const findFieldPrototype = (app, name, type) => {
|
|
|
124
130
|
}
|
|
125
131
|
};
|
|
126
132
|
|
|
133
|
+
const filterOutPrivateFieldsFromNormalizedFieldDescription = (
|
|
134
|
+
privateFields
|
|
135
|
+
) => {
|
|
136
|
+
return ({ destName }) => {
|
|
137
|
+
return !privateFields.includes(destName);
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const normalizeFieldsDescriptionsList = (list) => {
|
|
142
|
+
return list.map(parseFieldDescription);
|
|
143
|
+
};
|
|
144
|
+
module.exports.normalizeFieldsDescriptionsList =
|
|
145
|
+
normalizeFieldsDescriptionsList;
|
|
127
146
|
/**
|
|
128
147
|
* Creates fields UI representation schema from list of fields in DB model
|
|
129
148
|
* and library of fields
|
|
130
149
|
* @param {object} app notApplication instance
|
|
131
|
-
* @param {object}
|
|
150
|
+
* @param {object} rawFieldsList model db schema
|
|
132
151
|
* @param {Array<string|Array>} rawMutationsList fields mutations, for little tuning
|
|
133
152
|
* @param {Array<string>} privateFields fields to omit from result
|
|
134
153
|
* @param {string} moduleName for detailed reports on issues, in which module and what field is faulty
|
|
@@ -137,47 +156,82 @@ const findFieldPrototype = (app, name, type) => {
|
|
|
137
156
|
|
|
138
157
|
module.exports.initManifestFields = (
|
|
139
158
|
app, //notApplication
|
|
140
|
-
|
|
159
|
+
rawFieldsList, //raw fields list of model
|
|
141
160
|
rawMutationsList = [], //fields mutations
|
|
142
161
|
privateFields = [], //fields to omit
|
|
143
162
|
moduleName //module name for reporting
|
|
144
163
|
) => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
164
|
+
const //shallow copy of array
|
|
165
|
+
normalizedMutationsList = [
|
|
166
|
+
...normalizeFieldsDescriptionsList(rawMutationsList),
|
|
167
|
+
],
|
|
168
|
+
resultFields = [];
|
|
169
|
+
|
|
170
|
+
if (
|
|
171
|
+
rawFieldsList &&
|
|
172
|
+
Array.isArray(rawFieldsList) &&
|
|
173
|
+
rawFieldsList.length > 0
|
|
174
|
+
) {
|
|
175
|
+
const normalizedFieldsList =
|
|
176
|
+
normalizeFieldsDescriptionsList(rawFieldsList);
|
|
177
|
+
normalizedFieldsList
|
|
178
|
+
.filter(
|
|
179
|
+
filterOutPrivateFieldsFromNormalizedFieldDescription(
|
|
180
|
+
privateFields
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
.forEach((fieldDescription) => {
|
|
184
|
+
const { srcName, destName } = fieldDescription;
|
|
185
|
+
const fieldMutationDescription = getMutationForField(
|
|
186
|
+
destName,
|
|
187
|
+
normalizedMutationsList
|
|
188
|
+
);
|
|
189
|
+
if (fieldMutationDescription) {
|
|
190
|
+
resultFields.push({
|
|
191
|
+
srcName,
|
|
192
|
+
destName,
|
|
193
|
+
mutation: fieldMutationDescription.mutation,
|
|
194
|
+
});
|
|
195
|
+
normalizedMutationsList.splice(
|
|
196
|
+
normalizedMutationsList.indexOf(
|
|
197
|
+
fieldMutationDescription
|
|
198
|
+
),
|
|
199
|
+
1
|
|
200
|
+
);
|
|
157
201
|
} else {
|
|
158
|
-
|
|
202
|
+
resultFields.push({
|
|
203
|
+
srcName,
|
|
204
|
+
destName,
|
|
205
|
+
mutation: {},
|
|
206
|
+
});
|
|
159
207
|
}
|
|
160
208
|
});
|
|
161
|
-
|
|
209
|
+
resultFields.push(...normalizedMutationsList);
|
|
162
210
|
} else {
|
|
163
|
-
|
|
211
|
+
resultFields.push(...normalizedMutationsList);
|
|
164
212
|
}
|
|
165
|
-
return module.exports.createSchemaFromFields(
|
|
213
|
+
return module.exports.createSchemaFromFields(
|
|
214
|
+
app,
|
|
215
|
+
resultFields,
|
|
216
|
+
"ui",
|
|
217
|
+
moduleName
|
|
218
|
+
);
|
|
166
219
|
};
|
|
167
220
|
|
|
168
221
|
/**
|
|
169
222
|
* Returns mutation tuple for a field or false
|
|
170
|
-
* @param {string}
|
|
171
|
-
* @param {Array}
|
|
172
|
-
* @return {
|
|
223
|
+
* @param {string} destName field name
|
|
224
|
+
* @param {Array} normalizedFieldsList fields description lists
|
|
225
|
+
* @return {Object}
|
|
173
226
|
*/
|
|
174
|
-
function getMutationForField(
|
|
175
|
-
for (let
|
|
176
|
-
|
|
177
|
-
|
|
227
|
+
function getMutationForField(destName, normalizedFieldsList) {
|
|
228
|
+
for (let mutationFieldDescription of normalizedFieldsList) {
|
|
229
|
+
const { destName: mutationDest } = mutationFieldDescription;
|
|
230
|
+
if (mutationDest === destName) {
|
|
231
|
+
return mutationFieldDescription;
|
|
178
232
|
}
|
|
179
233
|
}
|
|
180
|
-
return
|
|
234
|
+
return null;
|
|
181
235
|
}
|
|
182
236
|
module.exports.getMutationForField = getMutationForField;
|
|
183
237
|
|
package/src/form/form.js
CHANGED
|
@@ -4,7 +4,7 @@ const notPath = require("not-path");
|
|
|
4
4
|
const notConfig = require("not-config");
|
|
5
5
|
const FormFabric = require("./fabric");
|
|
6
6
|
const Auth = require("../auth");
|
|
7
|
-
const { createSchemaFromFields } = require("../fields");
|
|
7
|
+
const { createSchemaFromFields, normalizeFieldsDescriptionsList } = require("../fields");
|
|
8
8
|
const notFieldsFilter = require("../fields/filter.js");
|
|
9
9
|
const getApp = require("../getApp.js");
|
|
10
10
|
const {
|
|
@@ -474,7 +474,7 @@ class Form {
|
|
|
474
474
|
#createModelSchema(app) {
|
|
475
475
|
return createSchemaFromFields(
|
|
476
476
|
app,
|
|
477
|
-
this.#PROTO_FIELDS,
|
|
477
|
+
normalizeFieldsDescriptionsList(this.#PROTO_FIELDS),
|
|
478
478
|
"model",
|
|
479
479
|
this.#FORM_NAME
|
|
480
480
|
);
|
|
@@ -4,34 +4,48 @@ const { initManifestFields } = require("../../fields");
|
|
|
4
4
|
const { firstLetterToUpper } = require("../../common");
|
|
5
5
|
|
|
6
6
|
const fieldsIsArray = (mod) => mod && Array.isArray(mod.fields);
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const getModelName = (routeManifest)=>firstLetterToUpper(routeManifest.model);
|
|
9
10
|
|
|
10
11
|
module.exports = class notModuleInitializatorManifests {
|
|
11
12
|
static openFile = require;
|
|
12
13
|
|
|
14
|
+
static getMutationsFromManifest(nModule,routeName){
|
|
15
|
+
const routeManifest = nModule.getRouteManifest(routeName);
|
|
16
|
+
if(fieldsIsArray(routeManifest)){
|
|
17
|
+
return [...routeManifest.fields];
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static extractPrivateFields(routeManifest){
|
|
23
|
+
const privateFields = [];
|
|
24
|
+
if (routeManifest.privateFields) {
|
|
25
|
+
privateFields.push(...(Array.isArray(routeManifest.privateFields) ? [...routeManifest.privateFields] : []));
|
|
26
|
+
delete routeManifest.privateFields;
|
|
27
|
+
}
|
|
28
|
+
return privateFields;
|
|
29
|
+
}
|
|
30
|
+
|
|
13
31
|
static run({ nModule }) {
|
|
14
32
|
const moduleName = nModule.getName();
|
|
15
33
|
for (let routeName in nModule.getRoutesManifests()) {
|
|
16
34
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
privateFields,
|
|
32
|
-
moduleName
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
+
const routeManifest = nModule.getRouteManifest(routeName);
|
|
36
|
+
const rawMutationsList = notModuleInitializatorManifests.getMutationsFromManifest(nModule, routeName);
|
|
37
|
+
const ModelName = getModelName(routeManifest);
|
|
38
|
+
const rawFieldsList = nModule.getModelFields(ModelName);
|
|
39
|
+
const privateFields = notModuleInitializatorManifests.extractPrivateFields(routeManifest);
|
|
40
|
+
|
|
41
|
+
routeManifest.fields = initManifestFields(
|
|
42
|
+
nModule.getApp(),
|
|
43
|
+
rawFieldsList,
|
|
44
|
+
rawMutationsList,
|
|
45
|
+
privateFields,
|
|
46
|
+
moduleName
|
|
47
|
+
);
|
|
48
|
+
|
|
35
49
|
} catch (e) {
|
|
36
50
|
error(
|
|
37
51
|
`Error while initialization of route: ${moduleName}//${routeName}`
|
package/src/manifest/module.js
CHANGED
|
@@ -171,6 +171,14 @@ class notModule {
|
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
getModelFields(modelName) {
|
|
175
|
+
const modelFile = this.getModelFile(modelName);
|
|
176
|
+
if (modelFile && objHas(modelFile, 'FIELDS') && modelFile.FIELDS) {
|
|
177
|
+
return modelFile.FIELDS;
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
|
|
174
182
|
expose(expressApp, moduleName) {
|
|
175
183
|
if (this.manifests && expressApp) {
|
|
176
184
|
notModuleInitializator.exec({ nModule: this });
|