@sera4/essentia 1.1.52 → 1.1.54
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 +2 -2
- package/package.tar.gz +0 -0
- package/serializer/index.js +32 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sera4/essentia",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.54",
|
|
4
4
|
"description": "A library of utilities for Teleporte Web Services",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"amqplib": "^0.8.0",
|
|
31
31
|
"async": "^3.2.2",
|
|
32
|
-
"axios": "^
|
|
32
|
+
"axios": "^1.6.2",
|
|
33
33
|
"deep-diff": "^1.0.2",
|
|
34
34
|
"diff": "^5.0.0",
|
|
35
35
|
"fast-safe-stringify": "^2.0.7",
|
package/package.tar.gz
CHANGED
|
Binary file
|
package/serializer/index.js
CHANGED
|
@@ -8,23 +8,53 @@ export default {
|
|
|
8
8
|
* @param {Object} Model the squelize model to add this plugin to
|
|
9
9
|
* @param {Object} options various options for serialization. These can be:
|
|
10
10
|
* • hide - an array of fields to be omitted
|
|
11
|
+
* • remove - an array of fields ot be REMOVED so they cannot be unhidden
|
|
11
12
|
* • decorators - an array of special decorators to run during serialization
|
|
13
|
+
* • handler - a handler for transforming data using only the values
|
|
14
|
+
* • advhandler - an advanced handler for transforming data using the value, object or options
|
|
15
|
+
* • includeAllFields - show fields that are normally hidden
|
|
16
|
+
* • includeFields[..] - show specific fields that are normally hidden
|
|
12
17
|
*/
|
|
13
18
|
serialize : (Model, options) => {
|
|
14
19
|
Model.prototype.toJSON = function(eachOptions={}) {
|
|
15
20
|
const hide = options && options.hide ? options.hide : [];
|
|
21
|
+
const remove = options && options.remove ? options.remove : [];
|
|
22
|
+
// ignore hide principles; but still do NOT show null
|
|
23
|
+
const includeAllFields = eachOptions["includeAllFields"];
|
|
24
|
+
|
|
25
|
+
// optionally force a normally hidden fields to be seen (by name)
|
|
26
|
+
const includeFields = eachOptions["includeFields"] || []
|
|
27
|
+
const handlerOptions = eachOptions["handlerOptions"] || {}
|
|
28
|
+
|
|
16
29
|
const values = this.get();
|
|
17
30
|
|
|
31
|
+
// for security reasons, some fields may need to be removed, such as
|
|
32
|
+
// password salts and mfa tokens
|
|
33
|
+
remove.forEach((field) => {
|
|
34
|
+
delete values[field];
|
|
35
|
+
});
|
|
36
|
+
|
|
18
37
|
if (options && options.decorators) {
|
|
19
38
|
options.decorators.forEach(dec => {
|
|
20
39
|
const k = dec.name;
|
|
21
40
|
const v = values[k];
|
|
22
|
-
|
|
41
|
+
// the advanced handler takes more parameters
|
|
42
|
+
if (dec.advHandler) {
|
|
43
|
+
values[k] = dec.advHandler(v, this, handlerOptions);
|
|
44
|
+
} else {
|
|
45
|
+
values[k] = dec.handler(v);
|
|
46
|
+
}
|
|
23
47
|
});
|
|
24
48
|
}
|
|
25
49
|
|
|
50
|
+
// hidden fields CAN be resurrected if NOT null, and forced to be
|
|
51
|
+
// included
|
|
26
52
|
let omitted = _.omitBy(values, (v, k) => {
|
|
27
|
-
|
|
53
|
+
if (v === null) return true;
|
|
54
|
+
|
|
55
|
+
let omitted = (includeAllFields ? false : hide.includes(k));
|
|
56
|
+
if (omitted && includeFields[k]) omitted = true ;
|
|
57
|
+
return omitted;
|
|
28
58
|
});
|
|
29
59
|
|
|
30
60
|
const s = eachOptions["serializer"];
|