not-node 5.1.22 → 5.1.25

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": "5.1.22",
3
+ "version": "5.1.25",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/common.js CHANGED
@@ -156,7 +156,8 @@ module.exports.executeFunctionAsAsync = executeFunctionAsAsync;
156
156
  **/
157
157
  module.exports.executeObjectFunction = async (obj, name, params) => {
158
158
  if (obj) {
159
- const proc = notPath.get(":" + name, obj);
159
+ const proc =
160
+ typeof obj == "object" ? notPath.get(":" + name, obj) : obj[name];
160
161
  return await executeFunctionAsAsync(proc, params);
161
162
  }
162
163
  };
@@ -6,6 +6,9 @@
6
6
  "list_navigation_next_button_label": "Next",
7
7
  "button_cancel_label": "Cancel",
8
8
  "button_apply_label": "Apply",
9
+ "action_details_label": "Details",
10
+ "action_update_label": "Update",
11
+ "action_delete_label": "Delete",
9
12
  "field_select_label": "Select",
10
13
  "field_value_is_empty_placeholder": "Empty",
11
14
  "loading_label": "Loading...",
@@ -64,5 +67,6 @@
64
67
  "crud_delete_action_waiting": "Deleting record...",
65
68
  "add_label": "Add",
66
69
  "select_from_list_label": "Select from list...",
67
- "field_actions_label": "Actions"
70
+ "field_actions_label": "Actions",
71
+ "form_exception_field_extractor_is_undefined": "Field extractor is undefined"
68
72
  }
@@ -11,6 +11,9 @@
11
11
  "loading_label": "Загрузка...",
12
12
  "button_cancel_label": "Отмена",
13
13
  "button_apply_label": "Применить",
14
+ "action_details_label": "Подробнее",
15
+ "action_update_label": "Изменить",
16
+ "action_delete_label": "Удалить",
14
17
  "form_validation_error": "Форма заполнена с ошибками",
15
18
  "field_active_label": "Активна",
16
19
  "field_codeName_label": "Псевдоним",
@@ -63,7 +66,8 @@
63
66
  "crud_delete_action_waiting": "Удаление записи...",
64
67
  "add_label": "Добавить",
65
68
  "select_from_list_label": "Выберите из списка...",
66
- "field_actions_label": "Действия"
69
+ "field_actions_label": "Действия",
70
+ "form_exception_field_extractor_is_undefined": "Экстрактор для поля входных данных отсутствует"
67
71
 
68
72
 
69
73
  }
@@ -0,0 +1,11 @@
1
+ const { notRequestError } = require("not-error");
2
+ class FormExceptionExtractorForFieldIsUndefined extends notRequestError {
3
+ constructor(fieldName) {
4
+ super("not-node:form_exception_field_extractor_is_undefined", {
5
+ fieldName,
6
+ });
7
+ }
8
+ }
9
+
10
+ module.exports.FormExceptionExtractorForFieldIsUndefined =
11
+ FormExceptionExtractorForFieldIsUndefined;
@@ -0,0 +1,3 @@
1
+ module.exports = (req) => {
2
+ return req.user ? req.user._id : undefined;
3
+ };
@@ -0,0 +1 @@
1
+ module.exports = () => "User";
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ activeUserId: require("./activeUserId.js"),
3
+ activeUserModelName: require("./activeUserModelName.js"),
4
+ fromBody: require("./fromBody.js"),
5
+ fromQuery: require("./fromQuery.js"),
6
+ fromParams: require("./fromParams.js"),
7
+ };
package/src/form/form.js CHANGED
@@ -9,9 +9,11 @@ const ValidationSession = require("not-validation").Session;
9
9
 
10
10
  const { notValidationError, notError } = require("not-error");
11
11
 
12
- const fromBody = require("./extractors/fromBody.js");
13
- const fromQuery = require("./extractors/fromQuery.js");
14
- const fromParams = require("./extractors/fromParams.js");
12
+ const {
13
+ FormExceptionExtractorForFieldIsUndefined,
14
+ } = require("../exceptions/form.js");
15
+
16
+ const DEFAULT_EXTRACTORS = require("./extractors");
15
17
 
16
18
  /**
17
19
  * Generic form validation class
@@ -31,9 +33,7 @@ class Form {
31
33
  #PROTO_FIELDS;
32
34
  #VALIDATOR;
33
35
  #EXTRACTORS = {
34
- fromQuery,
35
- fromBody,
36
- fromParams,
36
+ ...DEFAULT_EXTRACTORS,
37
37
  };
38
38
 
39
39
  constructor({ FIELDS, FORM_NAME, app, EXTRACTORS = {} }) {
@@ -226,11 +226,19 @@ class Form {
226
226
 
227
227
  extractByInstructions(req, instructions) {
228
228
  const results = {};
229
- for (let fieldName of instructions) {
229
+ for (let fieldName in instructions) {
230
230
  const instruction = instructions[fieldName];
231
- const extractor = this.#EXTRACTORS[instruction];
232
- if (isFunc(extractor)) {
233
- results[fieldName] = extractor(req, fieldName);
231
+ if (isFunc(instruction)) {
232
+ results[fieldName] = instruction(req, fieldName);
233
+ } else if (typeof instruction == "string") {
234
+ const extractor = this.#EXTRACTORS[instruction];
235
+ if (isFunc(extractor)) {
236
+ results[fieldName] = extractor(req, fieldName);
237
+ } else {
238
+ throw new FormExceptionExtractorForFieldIsUndefined(
239
+ fieldName
240
+ );
241
+ }
234
242
  }
235
243
  }
236
244
  return results;
@@ -383,7 +383,12 @@ function close() {
383
383
  return this.save();
384
384
  }
385
385
 
386
+ function saveNewVersion() {
387
+ return routine.update(this, { _id: this._id }, this.toObject());
388
+ }
389
+
386
390
  module.exports.thisMethods = {
387
391
  getID,
388
392
  close,
393
+ saveNewVersion,
389
394
  };
@@ -64,7 +64,7 @@ class ModelRoutine {
64
64
  filter.__latest = true;
65
65
  filter.__closed = false;
66
66
  const item = await model
67
- .findOneAndUpdate(filter, data, { returnOriginal: false })
67
+ .updateOne(filter, data, { returnOriginal: false })
68
68
  .exec();
69
69
  return model.saveVersion(item._id);
70
70
  }