not-node 5.1.18 → 5.1.21

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.18",
3
+ "version": "5.1.21",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,7 +13,6 @@ function getOwnerId(data, ownerFieldName = CONST.DOCUMENT_OWNER_FIELD_NAME) {
13
13
  return undefined;
14
14
  }
15
15
  if (
16
- objHas(data, ownerFieldName) &&
17
16
  data[ownerFieldName] &&
18
17
  COMMON.validateObjectId(data[ownerFieldName].toString())
19
18
  ) {
@@ -0,0 +1,3 @@
1
+ module.exports = (req, name) => {
2
+ return req.body[name];
3
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = (req, name) => {
2
+ return req.params[name];
3
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = (req, name) => {
2
+ return req.query[name];
3
+ };
package/src/form/form.js CHANGED
@@ -2,13 +2,17 @@ const FormFabric = require("./fabric");
2
2
 
3
3
  const { createSchemaFromFields } = require("../fields");
4
4
 
5
- const { objHas } = require("../common");
5
+ const { objHas, isFunc } = require("../common");
6
6
 
7
7
  const ValidationBuilder = require("not-validation").Builder;
8
8
  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");
15
+
12
16
  /**
13
17
  * Generic form validation class
14
18
  **/
@@ -26,12 +30,18 @@ class Form {
26
30
  #FORM_NAME;
27
31
  #PROTO_FIELDS;
28
32
  #VALIDATOR;
33
+ #EXTRACTORS = {
34
+ fromQuery,
35
+ fromBody,
36
+ fromParams,
37
+ };
29
38
 
30
- constructor({ FIELDS, FORM_NAME, app }) {
39
+ constructor({ FIELDS, FORM_NAME, app, EXTRACTORS = {} }) {
31
40
  this.#FORM_NAME = FORM_NAME;
32
41
  this.#PROTO_FIELDS = FIELDS;
33
42
  this.#createValidationSchema(app);
34
43
  this.#augmentValidationSchema();
44
+ this.#addExtractors(EXTRACTORS);
35
45
  }
36
46
 
37
47
  /**
@@ -207,6 +217,23 @@ class Form {
207
217
  static fabric() {
208
218
  return FormFabric;
209
219
  }
220
+
221
+ #addExtractors(extractors = {}) {
222
+ if (extractors) {
223
+ this.#EXTRACTORS = { ...this.#EXTRACTORS, ...extractors };
224
+ }
225
+ }
226
+
227
+ extractByInstructions(req, instructions) {
228
+ const results = {};
229
+ for (let fieldName of instructions) {
230
+ const instruction = instructions[fieldName];
231
+ if (isFunc(instruction)) {
232
+ results[fieldName] = instruction(req, fieldName);
233
+ }
234
+ }
235
+ return results;
236
+ }
210
237
  }
211
238
 
212
239
  module.exports = Form;