@contrail/transform-data 1.3.0-alpha.3 → 1.3.1
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/CHANGELOG.md +13 -0
- package/lib/common/object-path-util.js +11 -5
- package/package.json +3 -2
- package/.claude/settings.local.json +0 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@contrail/transform-data` are documented here.
|
|
4
|
+
|
|
5
|
+
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
|
+
Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [1.3.0] - (initial changelog entry)
|
|
11
|
+
|
|
12
|
+
- Initial changelog. Prior releases did not include a changelog.
|
|
13
|
+
See git history for changes predating this entry.
|
|
@@ -44,14 +44,17 @@ class ObjectPathUtil {
|
|
|
44
44
|
}
|
|
45
45
|
static setValueAtPath({ obj, pathParts, value, options, }) {
|
|
46
46
|
let current = obj;
|
|
47
|
-
let pathHasArrayIndex = false;
|
|
48
47
|
for (let i = 0; i < pathParts.length - 1; i++) {
|
|
49
48
|
const key = pathParts[i];
|
|
50
49
|
const isCurrentPartArrayIndex = ObjectPathUtil.isArrayIndexPart(key);
|
|
51
50
|
if (isCurrentPartArrayIndex) {
|
|
52
|
-
pathHasArrayIndex = true;
|
|
53
51
|
const idx = ObjectPathUtil.getArrayIndex(key);
|
|
54
52
|
ObjectPathUtil.ensureArrayFilledTo(current, idx);
|
|
53
|
+
const isNextPartArrayIndex = ObjectPathUtil.isArrayIndexPart(pathParts[i + 1]);
|
|
54
|
+
const isElementNotArray = isNextPartArrayIndex && !Array.isArray(current[idx]);
|
|
55
|
+
if (isElementNotArray) {
|
|
56
|
+
current[idx] = [];
|
|
57
|
+
}
|
|
55
58
|
current = current[idx];
|
|
56
59
|
continue;
|
|
57
60
|
}
|
|
@@ -68,11 +71,14 @@ class ObjectPathUtil {
|
|
|
68
71
|
if (isFinalKeyArrayIndex) {
|
|
69
72
|
const idx = ObjectPathUtil.getArrayIndex(finalKey);
|
|
70
73
|
ObjectPathUtil.ensureArrayFilledTo(current, idx);
|
|
71
|
-
current[idx]
|
|
74
|
+
const isArrayIndexEmpty = current[idx] == null || (typeof current[idx] === 'object' && Object.keys(current[idx]).length === 0);
|
|
75
|
+
if (options.shouldOverwriteExisting || isArrayIndexEmpty) {
|
|
76
|
+
current[idx] = value;
|
|
77
|
+
}
|
|
72
78
|
return;
|
|
73
79
|
}
|
|
74
|
-
const shouldWriteProperty =
|
|
75
|
-
if (shouldWriteProperty
|
|
80
|
+
const shouldWriteProperty = options.shouldOverwriteExisting || !Object.prototype.hasOwnProperty.call(current, finalKey);
|
|
81
|
+
if (shouldWriteProperty) {
|
|
76
82
|
current[finalKey] = value;
|
|
77
83
|
}
|
|
78
84
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/transform-data",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Libraries for transforming data",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
10
10
|
"lint": "tslint --fix -p tsconfig.json",
|
|
11
11
|
"test": "jest",
|
|
12
|
+
"test-debug": "npx jest --runInBand",
|
|
12
13
|
"test:watch": "jest --watch"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [],
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
49
|
"@contrail/sdk": "^1.5.3",
|
|
49
|
-
"@contrail/util": "^1.
|
|
50
|
+
"@contrail/util": "^1.3.0",
|
|
50
51
|
"node-fetch": "^3.2.10",
|
|
51
52
|
"require-from-url": "^3.1.3"
|
|
52
53
|
}
|