not-node 6.4.10 → 6.4.12

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.4.10",
3
+ "version": "6.4.12",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -151,7 +151,7 @@ module.exports.initManifestFields = (
151
151
  .filter((key) => !privateFields.includes(key))
152
152
  .forEach((key) => {
153
153
  let mutation = getMutationForField(key, mutationsList);
154
- if (mutation) {
154
+ if (mutation.length) {
155
155
  list.push(mutation);
156
156
  mutationsList.splice(mutationsList.indexOf(mutation), 1);
157
157
  } else {
@@ -169,7 +169,7 @@ module.exports.initManifestFields = (
169
169
  * Returns mutation tuple for a field or false
170
170
  * @param {string} name field name
171
171
  * @param {Array} list fields description lists
172
- * @return {boolean|Array<string|Object>}
172
+ * @return {Array<string|Object>}
173
173
  */
174
174
  function getMutationForField(name, list) {
175
175
  for (let item of list) {
@@ -177,7 +177,7 @@ function getMutationForField(name, list) {
177
177
  return item;
178
178
  }
179
179
  }
180
- return false;
180
+ return [];
181
181
  }
182
182
  module.exports.getMutationForField = getMutationForField;
183
183
 
package/src/form/form.js CHANGED
@@ -11,6 +11,7 @@ const {
11
11
  isFunc,
12
12
  firstLetterToUpper,
13
13
  firstLetterToLower,
14
+ copyObj,
14
15
  } = require("../common");
15
16
 
16
17
  const ValidationBuilder = require("not-validation").Builder;
@@ -97,7 +98,7 @@ class Form {
97
98
  * @param {import('../types.js').notAppFormRateLimiterOptions} options.rate
98
99
  */
99
100
  constructor({
100
- FIELDS,
101
+ FIELDS = [],
101
102
  FORM_NAME,
102
103
  MODEL_NAME,
103
104
  MODULE_NAME,
@@ -114,7 +115,7 @@ class Form {
114
115
  FORM_NAME ?? Form.createName(MODULE_NAME, MODEL_NAME, actionName);
115
116
  this.#MODEL_NAME = MODEL_NAME;
116
117
  this.#MODULE_NAME = MODULE_NAME;
117
- this.#PROTO_FIELDS = FIELDS;
118
+ this.#setFields(app, FIELDS);
118
119
  this.#createValidationSchema(app);
119
120
  this.#augmentValidationSchema();
120
121
  this.#addInstructions(INSTRUCTIONS);
@@ -125,6 +126,42 @@ class Form {
125
126
  this.#createRateLimiter(rate);
126
127
  }
127
128
 
129
+ #setFields(app, FIELDS = []) {
130
+ try {
131
+ const warning = () =>
132
+ app.logger.warn(`No PROTO_FIELDS for ${this.#FORM_NAME} form`);
133
+ if (FIELDS && Array.isArray(FIELDS) && FIELDS.length) {
134
+ this.#PROTO_FIELDS = FIELDS;
135
+ } else if (this.#MODEL_NAME) {
136
+ let modelPath = `${this.#MODEL_NAME}`;
137
+ if (this.#MODULE_NAME) {
138
+ modelPath = `${this.#MODULE_NAME}//${this.#MODEL_NAME}`;
139
+ }
140
+ //no path to model - returning after warning
141
+ if (!modelPath) {
142
+ warning();
143
+ return;
144
+ }
145
+ const mod = app.getModelFile(modelPath);
146
+ //no module or fields in module exports - returning after warning
147
+ if (
148
+ !(
149
+ mod &&
150
+ mod.FIELDS &&
151
+ Array.isArray(mod.FIELDS) &&
152
+ mod.FIELDS.length
153
+ )
154
+ ) {
155
+ warning();
156
+ return;
157
+ }
158
+ this.#PROTO_FIELDS = copyObj(mod.FIELDS);
159
+ }
160
+ } catch (e) {
161
+ app.logger.error(e);
162
+ }
163
+ }
164
+
128
165
  get FORM_NAME() {
129
166
  return this.#FORM_NAME;
130
167
  }
@@ -20,7 +20,7 @@ const extraActionsBuilder = (
20
20
  const POST_FIX_RECORD_ID = "/:record[_id]";
21
21
  const POST_FIX_ACTION_NAME = "/:actionName";
22
22
 
23
- module.exports = (MODULE_NAME, modelName, FIELDS, actions = {}) => {
23
+ module.exports = (MODULE_NAME, modelName, FIELDS = [], actions = {}) => {
24
24
  return {
25
25
  model: modelName,
26
26
  url: "/api/:modelName",