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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.5.31",
3
+ "version": "6.5.32",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- 'title', //for standart only name
35
- ['titleNonStandart', {component: 'UITextforBlind'}] //arrays of [name, mutation]
36
- ['someID', {}, 'ID'], //copy of standart ID field under name as someID
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((field) => {
46
+ fields.forEach((fieldDescription) => {
47
47
  let [schemaFieldName, schemaFieldValue] =
48
- module.exports.initSchemaField(app, field, false, type, moduleName);
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
- field,
62
+ fieldDescription,
57
63
  resultOnly = true,
58
64
  type = "ui",
59
65
  moduleName
60
66
  ) => {
61
67
  //log(field);
62
- let { srcName, destName, mutation } = parseFieldDescription(field);
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} schema model db schema
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
- schema, //schema of model
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
- let //shallow copy of array
146
- mutationsList = [...rawMutationsList],
147
- list = [];
148
- if (schema && Object.keys(schema).length > 0) {
149
- let rawKeys = Object.keys(schema);
150
- rawKeys
151
- .filter((key) => !privateFields.includes(key))
152
- .forEach((key) => {
153
- let mutation = getMutationForField(key, mutationsList);
154
- if (mutation.length) {
155
- list.push(mutation);
156
- mutationsList.splice(mutationsList.indexOf(mutation), 1);
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
- list.push(key);
202
+ resultFields.push({
203
+ srcName,
204
+ destName,
205
+ mutation: {},
206
+ });
159
207
  }
160
208
  });
161
- list.push(...mutationsList);
209
+ resultFields.push(...normalizedMutationsList);
162
210
  } else {
163
- list = mutationsList;
211
+ resultFields.push(...normalizedMutationsList);
164
212
  }
165
- return module.exports.createSchemaFromFields(app, list, "ui", moduleName);
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} name field name
171
- * @param {Array} list fields description lists
172
- * @return {Array<string|Object>}
223
+ * @param {string} destName field name
224
+ * @param {Array} normalizedFieldsList fields description lists
225
+ * @return {Object}
173
226
  */
174
- function getMutationForField(name, list) {
175
- for (let item of list) {
176
- if (Array.isArray(item) && item[0] === name) {
177
- return item;
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
- const extractPrivateFields = (mod) =>
8
- Array.isArray(mod.privateFields) ? [...mod.privateFields] : [];
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 mod = nModule.getRouteManifest(routeName);
18
- if (fieldsIsArray(mod)) {
19
- const rawMutationsList = [...mod.fields];
20
- const ModelName = firstLetterToUpper(mod.model);
21
- const schema = nModule.getModelSchema(ModelName);
22
- let privateFields = [];
23
- if (mod.privateFields) {
24
- privateFields = extractPrivateFields(mod);
25
- delete mod.privateFields;
26
- }
27
- mod.fields = initManifestFields(
28
- nModule.getApp(),
29
- schema,
30
- rawMutationsList,
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}`
@@ -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 });