not-node 6.3.80 → 6.3.82

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.3.80",
3
+ "version": "6.3.82",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/const.js CHANGED
@@ -4,10 +4,13 @@ const DEFAULT_PATH_MODULES = "./modules";
4
4
  const DEFAULT_PATH_WS = "./ws";
5
5
  const DEFAULT_PATH_DB_DUMPS = "../../db.dumps";
6
6
 
7
+ const ACTION_DATA_TYPES = require("./manifest/const").ACTION_DATA_TYPES;
8
+
7
9
  module.exports = {
8
10
  DEFAULT_PATH_WS,
9
11
  DEFAULT_PATH_MODULES,
10
12
  DEFAULT_PATH_STATIC,
11
13
  DEFAULT_PATH_TMP,
12
14
  DEFAULT_PATH_DB_DUMPS,
15
+ ACTION_DATA_TYPES,
13
16
  };
@@ -1,5 +1,28 @@
1
1
  const notFilter = require("not-filter");
2
2
  const getApp = require("../../getApp");
3
+ const ACTION_DATA_TYPES = require("../../manifest/const").ACTION_DATA_TYPES;
4
+
5
+ const extractors = Object.freeze({
6
+ [ACTION_DATA_TYPES.PAGER]: (result, req) => {
7
+ const pager = notFilter.pager.process(req);
8
+ if (pager) {
9
+ result.skip = pager.skip;
10
+ result.size = pager.size;
11
+ }
12
+ },
13
+ [ACTION_DATA_TYPES.SORTER]: (result, req, thisSchema) => {
14
+ result.sorter = notFilter.sorter.process(req, thisSchema);
15
+ },
16
+ [ACTION_DATA_TYPES.SEARCH]: (result, req, thisSchema) => {
17
+ result.search = notFilter.search.process(req, thisSchema);
18
+ },
19
+ [ACTION_DATA_TYPES.FILTER]: (result, req, thisSchema) => {
20
+ result.filter = notFilter.filter.process(req, thisSchema);
21
+ },
22
+ [ACTION_DATA_TYPES.RETURN]: (result, req, thisSchema) => {
23
+ result.return = notFilter.return.process(req, thisSchema);
24
+ },
25
+ });
3
26
 
4
27
  /**
5
28
  *
@@ -20,18 +43,20 @@ module.exports = (form, req) => {
20
43
  thisSchema = getApp().getModelSchema(`${MODEL_NAME}`);
21
44
  }
22
45
  if (thisSchema) {
23
- let skip, size;
24
- const pager = notFilter.pager.process(req), //skip,size
25
- sorter = notFilter.sorter.process(req, thisSchema),
26
- search = notFilter.search.process(req, thisSchema);
27
- let filter = notFilter.filter.process(req, thisSchema);
28
- if (pager) {
29
- skip = pager.skip;
30
- size = pager.size;
31
- }
46
+ let result = {};
47
+ const routeActionDataTypes = form.getActionDataDataTypes(req);
48
+ Object.values(ACTION_DATA_TYPES).forEach((dataType) => {
49
+ if (
50
+ routeActionDataTypes.includes(dataType) &&
51
+ Object.hasOwn(extractors, dataType)
52
+ ) {
53
+ extractors[dataType](result, req, thisSchema);
54
+ }
55
+ });
56
+
32
57
  return {
33
58
  name: "query",
34
- value: { skip, size, sorter, search, filter },
59
+ value: result, //{ skip, size, sorter, search, filter, return }
35
60
  };
36
61
  }
37
62
 
package/src/form/form.js CHANGED
@@ -32,6 +32,7 @@ const DEFAULT_ID_EXTRACTORS = require("./env_extractors");
32
32
  const DEFAULT_TRANSFORMERS = require("./transformers");
33
33
  const DEFAULT_AFTER_EXTRACT_TRANSFORMERS = [];
34
34
  const notAppIdentity = require("../identity/index.js");
35
+ const { ACTION_DATA_TYPES } = require("../const.js");
35
36
 
36
37
  /**
37
38
  * Generic form validation class
@@ -195,6 +196,26 @@ class Form {
195
196
  return undefined;
196
197
  }
197
198
 
199
+ /**
200
+ * Returns array of types of data in action. Is subset of values of ACTION_DATA_TYPES object.
201
+ *
202
+ * @param {import('../types').notNodeExpressRequest} req
203
+ * @return {Array<string>}
204
+ * @memberof Form
205
+ */
206
+ getActionDataDataTypes(req) {
207
+ if (
208
+ req &&
209
+ req.notRouteData &&
210
+ req.notRouteData.actionData &&
211
+ req.notRouteData.actionData.data &&
212
+ Array.isArray(req.notRouteData.actionData.data)
213
+ ) {
214
+ return req.notRouteData.actionData.data;
215
+ }
216
+ return [];
217
+ }
218
+
198
219
  /**
199
220
  *
200
221
  *
@@ -221,15 +242,19 @@ class Form {
221
242
  }
222
243
 
223
244
  /**
224
- * Extracts data, should be overriden
245
+ * Extracts data, may be be overriden
225
246
  * @param {import('../types').notNodeExpressRequest} req expressjs request object
226
247
  * @return {Promise<import('../types').PreparedData>} forma data
227
248
  **/
228
249
  async extract(req) {
229
- return {
250
+ /** @type {import('../types').PreparedData} */
251
+ let result = {
230
252
  ...this.extractRequestEnvs(req),
231
- data: this.#extractByBestInstructions(req),
232
253
  };
254
+ if (this.getActionDataDataTypes(req).includes(ACTION_DATA_TYPES.DATA)) {
255
+ result.data = this.#extractByBestInstructions(req);
256
+ }
257
+ return result;
233
258
  }
234
259
 
235
260
  #extractByBestInstructions(req) {
@@ -0,0 +1,17 @@
1
+ const ACTION_DATA_TYPE_DATA = "data";
2
+ const ACTION_DATA_TYPE_PAGER = "pager";
3
+ const ACTION_DATA_TYPE_SORTER = "sorter";
4
+ const ACTION_DATA_TYPE_FILTER = "filter";
5
+ const ACTION_DATA_TYPE_SEARCH = "search";
6
+ const ACTION_DATA_TYPE_RETURN = "return";
7
+
8
+ const ACTION_DATA_TYPES = Object.freeze({
9
+ DATA: ACTION_DATA_TYPE_DATA,
10
+ PAGER: ACTION_DATA_TYPE_PAGER,
11
+ SORTER: ACTION_DATA_TYPE_SORTER,
12
+ FILTER: ACTION_DATA_TYPE_FILTER,
13
+ SEARCH: ACTION_DATA_TYPE_SEARCH,
14
+ RETURN: ACTION_DATA_TYPE_RETURN,
15
+ });
16
+
17
+ module.exports.ACTION_DATA_TYPES = ACTION_DATA_TYPES;