not-node 6.3.81 → 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 +1 -1
- package/src/form/env_extractors/query.js +35 -10
- package/src/form/form.js +28 -3
package/package.json
CHANGED
|
@@ -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
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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,
|
|
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
|
-
|
|
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) {
|