not-node 5.1.21 → 5.1.24
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/common.js +2 -1
- package/src/core/locales/en.json +2 -1
- package/src/core/locales/ru.json +2 -1
- package/src/exceptions/form.js +11 -0
- package/src/form/extractors/activeUserId.js +3 -0
- package/src/form/extractors/activeUserModelName.js +1 -0
- package/src/form/extractors/index.js +7 -0
- package/src/form/form.js +16 -7
package/package.json
CHANGED
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 =
|
|
159
|
+
const proc =
|
|
160
|
+
typeof obj == "object" ? notPath.get(":" + name, obj) : obj[name];
|
|
160
161
|
return await executeFunctionAsAsync(proc, params);
|
|
161
162
|
}
|
|
162
163
|
};
|
package/src/core/locales/en.json
CHANGED
|
@@ -64,5 +64,6 @@
|
|
|
64
64
|
"crud_delete_action_waiting": "Deleting record...",
|
|
65
65
|
"add_label": "Add",
|
|
66
66
|
"select_from_list_label": "Select from list...",
|
|
67
|
-
"field_actions_label": "Actions"
|
|
67
|
+
"field_actions_label": "Actions",
|
|
68
|
+
"form_exception_field_extractor_is_undefined": "Field extractor is undefined"
|
|
68
69
|
}
|
package/src/core/locales/ru.json
CHANGED
|
@@ -63,7 +63,8 @@
|
|
|
63
63
|
"crud_delete_action_waiting": "Удаление записи...",
|
|
64
64
|
"add_label": "Добавить",
|
|
65
65
|
"select_from_list_label": "Выберите из списка...",
|
|
66
|
-
"field_actions_label": "Действия"
|
|
66
|
+
"field_actions_label": "Действия",
|
|
67
|
+
"form_exception_field_extractor_is_undefined": "Экстрактор для поля входных данных отсутствует"
|
|
67
68
|
|
|
68
69
|
|
|
69
70
|
}
|
|
@@ -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 @@
|
|
|
1
|
+
module.exports = () => "User";
|
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
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
35
|
-
fromBody,
|
|
36
|
-
fromParams,
|
|
36
|
+
...DEFAULT_EXTRACTORS,
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
constructor({ FIELDS, FORM_NAME, app, EXTRACTORS = {} }) {
|
|
@@ -226,10 +226,19 @@ class Form {
|
|
|
226
226
|
|
|
227
227
|
extractByInstructions(req, instructions) {
|
|
228
228
|
const results = {};
|
|
229
|
-
for (let fieldName
|
|
229
|
+
for (let fieldName in instructions) {
|
|
230
230
|
const instruction = instructions[fieldName];
|
|
231
231
|
if (isFunc(instruction)) {
|
|
232
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
|
+
}
|
|
233
242
|
}
|
|
234
243
|
}
|
|
235
244
|
return results;
|