not-node 5.1.34 → 5.1.35

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.34",
3
+ "version": "5.1.35",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
File without changes
@@ -0,0 +1,6 @@
1
+ module.exports = (form, req) => {
2
+ return {
3
+ name: "activeUser",
4
+ value: req.user,
5
+ };
6
+ };
@@ -1,5 +1,8 @@
1
1
  module.exports = {
2
2
  _id: require("./_id.js"),
3
3
  ID: require("./ID.js"),
4
+ activeUser: require("./activeUser.js"),
5
+ ip: require("./ip.js"),
6
+ query: require("./query.js"),
4
7
  modelNameID: require("./modelNameID.js"),
5
8
  };
@@ -0,0 +1,8 @@
1
+ const getIP = require("../../auth").getIP;
2
+
3
+ module.exports = (form, req) => {
4
+ return {
5
+ name: "ip",
6
+ value: getIP(req),
7
+ };
8
+ };
@@ -1,11 +1,11 @@
1
1
  const { firstLetterToLower } = require("../../common");
2
2
 
3
3
  module.exports = (form, req) => {
4
- const modelName = form.getModelName();
4
+ const modelName = form.getModelName(req);
5
5
  if (typeof modelName === "string") {
6
6
  const idFieldName = `${firstLetterToLower(modelName)}ID`;
7
7
  return {
8
- name: "targetID",
8
+ name: idFieldName,
9
9
  value: req.params[idFieldName],
10
10
  };
11
11
  }
@@ -0,0 +1,24 @@
1
+ const notFilter = require("not-filter");
2
+ const getApp = require("../../getApp");
3
+
4
+ module.exports = (form, req) => {
5
+ const MODULE_NAME = form.getModuleName();
6
+ const MODEL_NAME = form.getModelName(req);
7
+ if (MODEL_NAME && MODULE_NAME) {
8
+ const thisSchema = getApp().getModelSchema(
9
+ `${MODULE_NAME}//${MODEL_NAME}`
10
+ );
11
+ if (thisSchema) {
12
+ const { skip, size } = notFilter.pager.process(req), //skip,size
13
+ sorter = notFilter.sorter.process(req, thisSchema),
14
+ search = notFilter.search.process(req, thisSchema);
15
+ let filter = notFilter.filter.process(req, thisSchema);
16
+
17
+ return {
18
+ name: "query",
19
+ value: { skip, size, sorter, search, filter },
20
+ };
21
+ }
22
+ }
23
+ return undefined;
24
+ };
package/src/form/form.js CHANGED
@@ -1,8 +1,8 @@
1
1
  const FormFabric = require("./fabric");
2
- const getIP = require("../auth").getIP;
2
+
3
3
  const { createSchemaFromFields } = require("../fields");
4
4
 
5
- const { objHas, isFunc } = require("../common");
5
+ const { objHas, isFunc, firstLetterToUpper } = require("../common");
6
6
 
7
7
  const ValidationBuilder = require("not-validation").Builder;
8
8
  const ValidationSession = require("not-validation").Session;
@@ -14,7 +14,7 @@ const {
14
14
  } = require("../exceptions/form.js");
15
15
 
16
16
  const DEFAULT_EXTRACTORS = require("./extractors");
17
- const DEFAULT_ID_EXTRACTORS = require("./id_extractors");
17
+ const DEFAULT_ID_EXTRACTORS = require("./env_extractors");
18
18
 
19
19
  /**
20
20
  * Generic form validation class
@@ -38,7 +38,7 @@ class Form {
38
38
  ...DEFAULT_EXTRACTORS,
39
39
  };
40
40
 
41
- #ID_EXTRACTORS = {
41
+ #ENV_EXTRACTORS = {
42
42
  ...DEFAULT_ID_EXTRACTORS,
43
43
  };
44
44
 
@@ -48,7 +48,7 @@ class Form {
48
48
  MODEL_NAME,
49
49
  app,
50
50
  EXTRACTORS = {},
51
- ID_EXTRACTORS = {},
51
+ ENV_EXTRACTORS = {},
52
52
  }) {
53
53
  this.#FORM_NAME = FORM_NAME;
54
54
  this.#MODEL_NAME = MODEL_NAME;
@@ -56,11 +56,16 @@ class Form {
56
56
  this.#createValidationSchema(app);
57
57
  this.#augmentValidationSchema();
58
58
  this.#addExtractors(EXTRACTORS);
59
- this.#addIdExtractors(ID_EXTRACTORS);
59
+ this.#addEnvExtractors(ENV_EXTRACTORS);
60
60
  }
61
61
 
62
- getModelName() {
63
- return this.#MODEL_NAME;
62
+ getModelName(req) {
63
+ if (this.#MODEL_NAME) {
64
+ return this.#MODEL_NAME;
65
+ } else if (req) {
66
+ return firstLetterToUpper(req.notRouteData.modelName);
67
+ }
68
+ return undefined;
64
69
  }
65
70
 
66
71
  /**
@@ -83,22 +88,20 @@ class Form {
83
88
  **/
84
89
  async extract(req) {
85
90
  return {
86
- ...this.extractRequestIds(req),
87
- activeUser: req.user,
88
- ip: getIP(req),
91
+ ...this.extractRequestEnvs(req),
89
92
  data: this.extractByInstructionsFromRouteActionFields(req),
90
93
  };
91
94
  }
92
95
 
93
- #addIdExtractors(extractors = {}) {
96
+ #addEnvExtractors(extractors = {}) {
94
97
  if (extractors) {
95
- this.#ID_EXTRACTORS = { ...this.#ID_EXTRACTORS, ...extractors };
98
+ this.#ENV_EXTRACTORS = { ...this.#ENV_EXTRACTORS, ...extractors };
96
99
  }
97
100
  }
98
101
 
99
- extractRequestIds(req) {
102
+ extractRequestEnvs(req) {
100
103
  const result = {};
101
- Array.values(this.#ID_EXTRACTORS).forEach((extractor) => {
104
+ Array.values(this.#ENV_EXTRACTORS).forEach((extractor) => {
102
105
  const extracted = extractor(this, req);
103
106
  if (
104
107
  extracted &&
@@ -77,6 +77,7 @@ class notRoute {
77
77
  setRequestRouteData(req, actionName, rule) {
78
78
  req.notRouteData = {
79
79
  actionName,
80
+ modelName: this.routeName,
80
81
  rule: copyObj(rule),
81
82
  actionData: copyObj(this.actionData),
82
83
  };