@trash-streamers/common 1.2.26 → 1.2.28
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.
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyFieldMask = applyFieldMask;
|
|
4
|
+
exports.generateFieldMask = generateFieldMask;
|
|
5
|
+
function applyFieldMask(sourceObject, fieldMask) {
|
|
6
|
+
if (!_isObject(sourceObject)) {
|
|
7
|
+
return sourceObject;
|
|
8
|
+
}
|
|
9
|
+
const result = {};
|
|
10
|
+
for (let i = 0; i < fieldMask.length; i++) {
|
|
11
|
+
const path = unescapeAndSplit(fieldMask[i]);
|
|
12
|
+
const sourceValue = internalGet(sourceObject, path);
|
|
13
|
+
internalSet(result, path, sourceValue);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
function generateFieldMask(object) {
|
|
18
|
+
const paths = [];
|
|
19
|
+
if (!_isObject(object)) {
|
|
20
|
+
return paths;
|
|
21
|
+
}
|
|
22
|
+
_generatePathForObject(object, "", paths);
|
|
23
|
+
return paths;
|
|
24
|
+
}
|
|
25
|
+
function unescapeAndSplit(originalPath) {
|
|
26
|
+
const properties = [];
|
|
27
|
+
let path = originalPath;
|
|
28
|
+
let i = path.indexOf(".");
|
|
29
|
+
while (i >= 0) {
|
|
30
|
+
if (isEscapedDot(path, i)) {
|
|
31
|
+
path = path.replace("\\.", ".");
|
|
32
|
+
i = path.indexOf(".", i);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const firstProperty = path.substring(0, i);
|
|
36
|
+
properties.push(firstProperty.replace(/\\\\/g, "\\"));
|
|
37
|
+
path = path.substring(i + 1);
|
|
38
|
+
i = path.indexOf(".");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
properties.push(path.replace(/\\\\/g, "\\"));
|
|
42
|
+
return properties;
|
|
43
|
+
}
|
|
44
|
+
function isEscapedDot(path, i) {
|
|
45
|
+
let counter = 0;
|
|
46
|
+
while (path.substring(i - 1, i) === "\\") {
|
|
47
|
+
counter++;
|
|
48
|
+
i--;
|
|
49
|
+
}
|
|
50
|
+
return counter % 2 === 1;
|
|
51
|
+
}
|
|
52
|
+
function _generatePathForObject(object, path, paths) {
|
|
53
|
+
for (let property in object) {
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(object, property)) {
|
|
55
|
+
let expandedPath = path.length > 0 ? path + "." : path;
|
|
56
|
+
expandedPath += property.replace(/\\/g, "\\\\").replace(/\./g, "\\.");
|
|
57
|
+
const objProperty = object[property];
|
|
58
|
+
if (objProperty instanceof Date && !isNaN(objProperty.getTime())) {
|
|
59
|
+
paths.push(expandedPath);
|
|
60
|
+
}
|
|
61
|
+
if (_isObject(objProperty) && !Array.isArray(objProperty)) {
|
|
62
|
+
_generatePathForObject(objProperty, expandedPath, paths);
|
|
63
|
+
}
|
|
64
|
+
else if (typeof objProperty !== "function") {
|
|
65
|
+
paths.push(expandedPath);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function _isObject(object) {
|
|
71
|
+
return typeof object === "object" && object !== null;
|
|
72
|
+
}
|
|
73
|
+
function internalSet(obj, path, value) {
|
|
74
|
+
if (value === undefined)
|
|
75
|
+
return;
|
|
76
|
+
path.reduce((acc, part, i) => {
|
|
77
|
+
if (i === path.length - 1) {
|
|
78
|
+
acc[part] = value;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
if (!acc[part] || typeof acc[part] !== "object")
|
|
82
|
+
acc[part] = {};
|
|
83
|
+
}
|
|
84
|
+
return acc[part];
|
|
85
|
+
}, obj);
|
|
86
|
+
}
|
|
87
|
+
function internalGet(obj, parts) {
|
|
88
|
+
return parts.reduce((acc, part) => (acc && acc[part] !== undefined ? acc[part] : undefined), obj);
|
|
89
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trash-streamers/common",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.28",
|
|
4
4
|
"description": "Core shared component for Trash-streamers microservice ecosystem",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@nestjs/common": "^11.1.12",
|
|
31
31
|
"@nestjs/config": "^4.0.2",
|
|
32
|
-
"@trash-streamers/contracts": "^1.1.
|
|
32
|
+
"@trash-streamers/contracts": "^1.1.64"
|
|
33
33
|
}
|
|
34
34
|
}
|