data-restructor 3.3.3 → 3.4.0
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/.github/ISSUE_TEMPLATE/bug_report.md +2 -2
- package/.github/workflows/codeql-analysis.yml +4 -4
- package/.github/workflows/continuous-integration.yaml +84 -0
- package/CHANGELOG.md +103 -75
- package/CONTRIBUTING.md +51 -43
- package/Commands.md +15 -15
- package/README.md +188 -137
- package/SECURITY.md +15 -0
- package/coverage/coverage-summary.json +4 -4
- package/coverage/datarestructor.js.html +446 -320
- package/coverage/describedfield.js.html +47 -47
- package/coverage/index.html +19 -19
- package/coverage/templateResolver.js.html +26 -26
- package/devdist/datarestructor-global-all.js +65 -23
- package/devdist/datarestructor-ie-global-all.js +65 -23
- package/devdist/datarestructor-ie.js +1479 -1616
- package/devdist/datarestructor.js +1439 -1559
- package/devdist/describedfield-ie.js +259 -279
- package/devdist/describedfield.js +257 -277
- package/devdist/templateResolver-ie.js +220 -252
- package/devdist/templateResolver.js +196 -227
- package/dist/datarestructor-global-all-min.js +1 -1
- package/dist/datarestructor-ie-global-all-min.js +1 -1
- package/dist/datarestructor-ie.js +1 -1
- package/dist/datarestructor-ie.js.map +1 -1
- package/dist/datarestructor.js +1 -1
- package/dist/datarestructor.js.map +1 -1
- package/dist/describedfield-ie.js +1 -1
- package/dist/describedfield-ie.js.map +1 -1
- package/dist/describedfield.js +1 -1
- package/dist/describedfield.js.map +1 -1
- package/dist/templateResolver-ie.js +1 -1
- package/dist/templateResolver-ie.js.map +1 -1
- package/dist/templateResolver.js +1 -1
- package/dist/templateResolver.js.map +1 -1
- package/docs/datarestructor.js.html +66 -24
- package/docs/describedfield.js.html +1 -1
- package/docs/index.html +49 -44
- package/docs/module-datarestructor.DescribedEntryCreator.html +1 -1
- package/docs/module-datarestructor.PropertyStructureDescriptionBuilder.html +1 -1
- package/docs/module-datarestructor.Restructor.html +3 -3
- package/docs/module-datarestructor.Transform.html +7 -30
- package/docs/module-datarestructor.html +100 -3
- package/docs/module-described_field.DescribedDataFieldBuilder.html +1 -1
- package/docs/module-described_field.DescribedDataFieldGroup.html +1 -1
- package/docs/module-described_field.html +1 -1
- package/docs/module-template_resolver.Resolver.html +1 -1
- package/docs/module-template_resolver.html +1 -1
- package/docs/templateResolver.js.html +1 -1
- package/package.json +16 -14
- package/renovate.json +20 -0
- package/src/js/datarestructor.js +65 -23
- package/test/js/DataRestructorUseCaseTest.js +36 -0
- package/.github/workflows/action.yaml +0 -44
|
@@ -1250,6 +1250,80 @@ It contains all functions to convert an object (e.g. parsed JSON) into uniform e
|
|
|
1250
1250
|
|
|
1251
1251
|
|
|
1252
1252
|
|
|
1253
|
+
<h4 class="name" id=".DescribedFieldRecursionContext">DescribedFieldRecursionContext</h4>
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
<div class="description">
|
|
1259
|
+
<p>Describes the context type for the recursive DescribedDataField conversion,
|
|
1260
|
+
that contains everything that needs to be accessible throughout recursion regardless of the
|
|
1261
|
+
recursion depth.</p>
|
|
1262
|
+
</div>
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
<h5>Type:</h5>
|
|
1267
|
+
<ul>
|
|
1268
|
+
<li>
|
|
1269
|
+
|
|
1270
|
+
<span class="param-type">Object</span>
|
|
1271
|
+
|
|
1272
|
+
|
|
1273
|
+
</li>
|
|
1274
|
+
</ul>
|
|
1275
|
+
|
|
1276
|
+
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
|
|
1280
|
+
<dl class="details">
|
|
1281
|
+
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
|
|
1285
|
+
|
|
1286
|
+
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
|
|
1290
|
+
|
|
1291
|
+
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
|
|
1295
|
+
|
|
1296
|
+
|
|
1297
|
+
|
|
1298
|
+
|
|
1299
|
+
|
|
1300
|
+
|
|
1301
|
+
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
<dt class="tag-source">Source:</dt>
|
|
1308
|
+
<dd class="tag-source"><ul class="dummy"><li>
|
|
1309
|
+
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#line1091">line 1091</a>
|
|
1310
|
+
</li></ul></dd>
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
</dl>
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
|
|
1325
|
+
|
|
1326
|
+
|
|
1253
1327
|
<h4 class="name" id=".ExtractedIndices">ExtractedIndices</h4>
|
|
1254
1328
|
|
|
1255
1329
|
|
|
@@ -1397,7 +1471,7 @@ It contains all functions to convert an object (e.g. parsed JSON) into uniform e
|
|
|
1397
1471
|
|
|
1398
1472
|
|
|
1399
1473
|
|
|
1400
|
-
<h4 class="name" id=".onEntryFoundFunction"><span class="type-signature"></span>onEntryFoundFunction<span class="signature">(groupName, foundEntry)</span><span class="type-signature"></span></h4>
|
|
1474
|
+
<h4 class="name" id=".onEntryFoundFunction"><span class="type-signature"></span>onEntryFoundFunction<span class="signature">(groupName, foundEntry, allEntries)</span><span class="type-signature"></span></h4>
|
|
1401
1475
|
|
|
1402
1476
|
|
|
1403
1477
|
|
|
@@ -1484,6 +1558,29 @@ It contains all functions to convert an object (e.g. parsed JSON) into uniform e
|
|
|
1484
1558
|
</tr>
|
|
1485
1559
|
|
|
1486
1560
|
|
|
1561
|
+
|
|
1562
|
+
<tr>
|
|
1563
|
+
|
|
1564
|
+
<td class="name"><code>allEntries</code></td>
|
|
1565
|
+
|
|
1566
|
+
|
|
1567
|
+
<td class="type">
|
|
1568
|
+
|
|
1569
|
+
|
|
1570
|
+
<span class="param-type">Array.<<a href="module-datarestructor.html#.DescribedEntry">module:datarestructor.DescribedEntry</a>></span>
|
|
1571
|
+
|
|
1572
|
+
|
|
1573
|
+
|
|
1574
|
+
</td>
|
|
1575
|
+
|
|
1576
|
+
|
|
1577
|
+
|
|
1578
|
+
|
|
1579
|
+
|
|
1580
|
+
<td class="description last"><p>the array of all entries where the found entry is an element of.</p></td>
|
|
1581
|
+
</tr>
|
|
1582
|
+
|
|
1583
|
+
|
|
1487
1584
|
</tbody>
|
|
1488
1585
|
</table>
|
|
1489
1586
|
|
|
@@ -1521,7 +1618,7 @@ It contains all functions to convert an object (e.g. parsed JSON) into uniform e
|
|
|
1521
1618
|
|
|
1522
1619
|
<dt class="tag-source">Source:</dt>
|
|
1523
1620
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
1524
|
-
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#
|
|
1621
|
+
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#line1182">line 1182</a>
|
|
1525
1622
|
</li></ul></dd>
|
|
1526
1623
|
|
|
1527
1624
|
|
|
@@ -2673,7 +2770,7 @@ how the data should be transformed.</p>
|
|
|
2673
2770
|
<br class="clear">
|
|
2674
2771
|
|
|
2675
2772
|
<footer>
|
|
2676
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
2773
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Oct 31 2022 17:00:02 GMT+0000 (Coordinated Universal Time)
|
|
2677
2774
|
</footer>
|
|
2678
2775
|
|
|
2679
2776
|
<script> prettyPrint(); </script>
|
|
@@ -2123,7 +2123,7 @@ Example: "responses[2].hits.hits[4]._source.name" will have an index o
|
|
|
2123
2123
|
<br class="clear">
|
|
2124
2124
|
|
|
2125
2125
|
<footer>
|
|
2126
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
2126
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Oct 31 2022 17:00:02 GMT+0000 (Coordinated Universal Time)
|
|
2127
2127
|
</footer>
|
|
2128
2128
|
|
|
2129
2129
|
<script> prettyPrint(); </script>
|
|
@@ -577,7 +577,7 @@ that contain an array of sub fields of the same type <a href="module-described_f
|
|
|
577
577
|
<br class="clear">
|
|
578
578
|
|
|
579
579
|
<footer>
|
|
580
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
580
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Oct 31 2022 17:00:02 GMT+0000 (Coordinated Universal Time)
|
|
581
581
|
</footer>
|
|
582
582
|
|
|
583
583
|
<script> prettyPrint(); </script>
|
|
@@ -783,7 +783,7 @@ Dynamically added properties represent custom named groups containing DescribedD
|
|
|
783
783
|
<br class="clear">
|
|
784
784
|
|
|
785
785
|
<footer>
|
|
786
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
786
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Oct 31 2022 17:00:02 GMT+0000 (Coordinated Universal Time)
|
|
787
787
|
</footer>
|
|
788
788
|
|
|
789
789
|
<script> prettyPrint(); </script>
|
|
@@ -1285,7 +1285,7 @@ Parts of the index can be inserted by using e.g. "{{index[1]}}".</p>
|
|
|
1285
1285
|
<br class="clear">
|
|
1286
1286
|
|
|
1287
1287
|
<footer>
|
|
1288
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
1288
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Oct 31 2022 17:00:02 GMT+0000 (Coordinated Universal Time)
|
|
1289
1289
|
</footer>
|
|
1290
1290
|
|
|
1291
1291
|
<script> prettyPrint(); </script>
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
<br class="clear">
|
|
164
164
|
|
|
165
165
|
<footer>
|
|
166
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
166
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Oct 31 2022 17:00:02 GMT+0000 (Coordinated Universal Time)
|
|
167
167
|
</footer>
|
|
168
168
|
|
|
169
169
|
<script> prettyPrint(); </script>
|
|
@@ -210,7 +210,7 @@ template_resolver.Resolver = (function () {
|
|
|
210
210
|
<br class="clear">
|
|
211
211
|
|
|
212
212
|
<footer>
|
|
213
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
213
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Oct 31 2022 17:00:02 GMT+0000 (Coordinated Universal Time)
|
|
214
214
|
</footer>
|
|
215
215
|
|
|
216
216
|
<script> prettyPrint(); </script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-restructor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Transforms parsed JSON objects into a uniform data structure",
|
|
5
5
|
"directories": {
|
|
6
6
|
"test": "test"
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"context": "node",
|
|
11
11
|
"includeNodeModules": true,
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": "
|
|
13
|
+
"node": "14"
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"engines": {
|
|
18
|
-
"node": "
|
|
18
|
+
"node": "18"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"prebuild": "rm -rf dist",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"coverage": "nyc npm run test",
|
|
25
25
|
"coverage-badge": "istanbul-badges-readme",
|
|
26
26
|
"doc": "jsdoc -d docs --configure ./docs/jsdoc.json --readme ./README.md ./src/js/*.js",
|
|
27
|
-
"merger": "merger build",
|
|
27
|
+
"merger": "echo -ne \"k\n\" | npx merger build",
|
|
28
28
|
"dev": "rm -rf devdist && parcel --out-dir devdist ./src/js/*.js",
|
|
29
29
|
"devbuild": "rm -rf devdist && NODE_ENV=development parcel build --dist-dir devdist ./src/js/*.js --no-optimize --no-source-maps --no-scope-hoist --no-content-hash --detailed-report",
|
|
30
|
-
"build": "parcel build ./src/js/*.js",
|
|
31
|
-
"package": "npm run lint && npm run coverage && npm run coverage-badge && npm run doc && npm run devbuild && npm run build && merger"
|
|
30
|
+
"build": "export NODE_OPTIONS=--no-experimental-fetch;parcel build ./src/js/*.js",
|
|
31
|
+
"package": "npm run lint && npm run coverage && npm run coverage-badge && npm run doc && npm run devbuild && npm run build && npm run merger"
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|
|
34
34
|
"type": "git",
|
|
@@ -46,12 +46,14 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://joht.github.io/data-restructor-js",
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"eslint": "
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
"eslint": "8.26.0",
|
|
50
|
+
"inquirer": "9.1.4",
|
|
51
|
+
"istanbul-badges-readme": "1.8.2",
|
|
52
|
+
"jasmine": "4.5.0",
|
|
53
|
+
"jsdoc": "3.6.11",
|
|
54
|
+
"merger-js": "3.10.3",
|
|
55
|
+
"node-notifier": "10.0.1",
|
|
56
|
+
"nyc": "15.1.0",
|
|
57
|
+
"parcel": "2.0.0"
|
|
58
|
+
}
|
|
57
59
|
}
|
package/renovate.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"config:base",
|
|
4
|
+
":pinAllExceptPeerDependencies",
|
|
5
|
+
":combinePatchMinorReleases",
|
|
6
|
+
":prConcurrentLimit10",
|
|
7
|
+
":automergeDigest",
|
|
8
|
+
":automergePatch",
|
|
9
|
+
":automergeMinor",
|
|
10
|
+
":automergeRequireAllStatusChecks",
|
|
11
|
+
":automergeLinters",
|
|
12
|
+
":automergeTesters"
|
|
13
|
+
],
|
|
14
|
+
"packageRules": [
|
|
15
|
+
{
|
|
16
|
+
"matchPackageNames": ["parcel"],
|
|
17
|
+
"enabled": false
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
package/src/js/datarestructor.js
CHANGED
|
@@ -1083,11 +1083,22 @@ datarestructor.Transform = (function () {
|
|
|
1083
1083
|
var describedEntity;
|
|
1084
1084
|
for (index = 0; index < describedEntries.length; index += 1) {
|
|
1085
1085
|
describedEntity = describedEntries[index];
|
|
1086
|
-
result.push(toDescribedField(describedEntity, 0, config));
|
|
1086
|
+
result.push(toDescribedField(describedEntity, {recursionDepth:0, config: config, groupToSkip:""}));
|
|
1087
1087
|
}
|
|
1088
1088
|
return result;
|
|
1089
1089
|
}
|
|
1090
1090
|
|
|
1091
|
+
/**
|
|
1092
|
+
* Describes the context type for the recursive DescribedDataField conversion,
|
|
1093
|
+
* that contains everything that needs to be accessible throughout recursion regardless of the
|
|
1094
|
+
* recursion depth.
|
|
1095
|
+
*
|
|
1096
|
+
* @typedef {Object} module:datarestructor.DescribedFieldRecursionContext
|
|
1097
|
+
* @param {number} recursionDepth current recursion depth
|
|
1098
|
+
* @param {String} groupToSkip name of a group to skip or "" when no group should be skipped.
|
|
1099
|
+
* @param {module:datarestructor.TransformConfig} config configuration for the data transformation
|
|
1100
|
+
*/
|
|
1101
|
+
|
|
1091
1102
|
/**
|
|
1092
1103
|
* Converts a internal described entry to a newly created public described field.
|
|
1093
1104
|
* Since the structure of a described field is hierarchical, this function is called recursively.
|
|
@@ -1095,13 +1106,12 @@ datarestructor.Transform = (function () {
|
|
|
1095
1106
|
* needs to be limited. Therefore, the current recursion depth is taken as second parameter
|
|
1096
1107
|
* and the maximum recursion depth is taken as third parameter.
|
|
1097
1108
|
* @param {module:datarestructor.DescribedEntry} entry the internal entry that will be converted
|
|
1098
|
-
* @param {
|
|
1099
|
-
* @param {module:datarestructor.TransformConfig} config configuration for the data transformation
|
|
1109
|
+
* @param {module:datarestructor.DescribedFieldRecursionContext} recursionContext context contains everything that needs to be accessible throughout the recursion.
|
|
1100
1110
|
* @returns {module:described_field.DescribedDataField}
|
|
1101
1111
|
* @protected
|
|
1102
1112
|
* @memberof module:datarestructor.Transform
|
|
1103
1113
|
*/
|
|
1104
|
-
function toDescribedField(entry,
|
|
1114
|
+
function toDescribedField(entry, recursionContext) {
|
|
1105
1115
|
var field = new described_field.DescribedDataFieldBuilder()
|
|
1106
1116
|
.category(entry.category)
|
|
1107
1117
|
.type(entry.type)
|
|
@@ -1112,37 +1122,70 @@ datarestructor.Transform = (function () {
|
|
|
1112
1122
|
.fieldName(entry.fieldName)
|
|
1113
1123
|
.value(entry.value)
|
|
1114
1124
|
.build();
|
|
1115
|
-
if (recursionDepth > config.maxRecursionDepth) {
|
|
1125
|
+
if (recursionContext.recursionDepth > recursionContext.config.maxRecursionDepth) {
|
|
1116
1126
|
return field;
|
|
1117
1127
|
}
|
|
1128
|
+
var nextRecursionContext = null;
|
|
1129
|
+
var duplicateGroupNameToSkip = "";
|
|
1118
1130
|
var fieldGroups = new described_field.DescribedDataFieldGroup(field);
|
|
1119
|
-
forEachGroupEntry(entry, function (groupName, groupEntry) {
|
|
1120
|
-
if (
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
if (config.debugMode) {
|
|
1124
|
-
console.log(
|
|
1125
|
-
"Removed duplicate field " +
|
|
1126
|
-
groupEntry.fieldName +
|
|
1127
|
-
" with value " +
|
|
1128
|
-
groupEntry.value +
|
|
1129
|
-
" of group " +
|
|
1130
|
-
groupName +
|
|
1131
|
-
" at recursion depth " +
|
|
1132
|
-
recursionDepth
|
|
1133
|
-
);
|
|
1131
|
+
forEachGroupEntry(entry, function (groupName, groupEntry, allGroupEntries) {
|
|
1132
|
+
if (recursionContext.groupToSkip === groupName) {
|
|
1133
|
+
if (recursionContext.config.debugMode) {
|
|
1134
|
+
console.log("Removed duplicate group " + groupName + " at recursion depth " + recursionContext.recursionDepth);
|
|
1134
1135
|
}
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
duplicateGroupNameToSkip = "";
|
|
1139
|
+
if (recursionContext.recursionDepth >= recursionContext.config.removeDuplicationAboveRecursionDepth) {
|
|
1140
|
+
duplicateGroupNameToSkip = arraysEqual(groupEntry[groupName], allGroupEntries, describedFieldEqual)? groupName : "";
|
|
1135
1141
|
}
|
|
1142
|
+
nextRecursionContext = {recursionDepth: recursionContext.recursionDepth + 1, config: recursionContext.config, groupToSkip: duplicateGroupNameToSkip};
|
|
1143
|
+
fieldGroups.addGroupEntry(groupName, toDescribedField(groupEntry, nextRecursionContext));
|
|
1136
1144
|
});
|
|
1137
1145
|
return field;
|
|
1138
1146
|
}
|
|
1139
1147
|
|
|
1148
|
+
function describedFieldEqual(a, b) {
|
|
1149
|
+
return (
|
|
1150
|
+
defaultEmpty(a.category) === defaultEmpty(b.category) &&
|
|
1151
|
+
defaultEmpty(a.type) === defaultEmpty(b.type) &&
|
|
1152
|
+
a.fieldName === b.fieldName &&
|
|
1153
|
+
a.value === b.value
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
function defaultEmpty(value) {
|
|
1158
|
+
return defaultValue(value, "");
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
function defaultValue(value, valueAsDefault) {
|
|
1162
|
+
if (typeof value === "undefined" || !value) {
|
|
1163
|
+
return valueAsDefault;
|
|
1164
|
+
}
|
|
1165
|
+
return value;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// Reference: https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript/16430730
|
|
1169
|
+
// Added "elementEqualFunction" to implement equal object detection.
|
|
1170
|
+
// Arrays are assumed to be sorted. Differently ordered entries are treated as not equal.
|
|
1171
|
+
function arraysEqual(a, b, elementEqualFunction) {
|
|
1172
|
+
if (a === b) return true;
|
|
1173
|
+
if (a == null || b == null) return false;
|
|
1174
|
+
if (a.length !== b.length) return false;
|
|
1175
|
+
|
|
1176
|
+
for (var i = 0; i < a.length; ++i) {
|
|
1177
|
+
if (!elementEqualFunction(a[i], b[i])) return false;
|
|
1178
|
+
}
|
|
1179
|
+
return true;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1140
1182
|
/**
|
|
1141
1183
|
* Takes the full qualified original property name and extracts a simple name out of it.
|
|
1142
1184
|
*
|
|
1143
1185
|
* @callback module:datarestructor.onEntryFoundFunction
|
|
1144
1186
|
* @param {string} groupName name of the group where the entry had been found.
|
|
1145
1187
|
* @param {module:datarestructor.DescribedEntry} foundEntry the found entry itself.
|
|
1188
|
+
* @param {module:datarestructor.DescribedEntry[]} allEntries the array of all entries where the found entry is an element of.
|
|
1146
1189
|
*/
|
|
1147
1190
|
|
|
1148
1191
|
/**
|
|
@@ -1160,13 +1203,12 @@ datarestructor.Transform = (function () {
|
|
|
1160
1203
|
groupName = rootEntry.groupNames[groupIndex];
|
|
1161
1204
|
for (entryIndex = 0; entryIndex < rootEntry[groupName].length; entryIndex += 1) {
|
|
1162
1205
|
entry = rootEntry[groupName][entryIndex];
|
|
1163
|
-
onFoundEntry(groupName, entry);
|
|
1206
|
+
onFoundEntry(groupName, entry, rootEntry[groupName]);
|
|
1164
1207
|
}
|
|
1165
1208
|
}
|
|
1166
1209
|
}
|
|
1167
|
-
|
|
1168
1210
|
return Transform;
|
|
1169
|
-
}
|
|
1211
|
+
}());
|
|
1170
1212
|
|
|
1171
1213
|
/**
|
|
1172
1214
|
* Main fassade for the data restructor as static function(s).
|
|
@@ -432,5 +432,41 @@ describe("datarestructor.Restructor (use case)", function () {
|
|
|
432
432
|
);
|
|
433
433
|
});
|
|
434
434
|
});
|
|
435
|
+
|
|
436
|
+
describe("using Transform with duplication removal", function () {
|
|
437
|
+
beforeEach(function () {
|
|
438
|
+
restructorResults = new datarestructor.Transform(descriptions).setRemoveDuplicationAboveRecursionDepth(0).setMaxRecursionDepth(1).enableDebugMode().processJson(jsonData);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it("shouldn't contain duplicated details inside every summary detail", function () {
|
|
442
|
+
forEachEntryMatching(
|
|
443
|
+
function (entry) {
|
|
444
|
+
return entry.type === "summary";
|
|
445
|
+
},
|
|
446
|
+
function (entry) {
|
|
447
|
+
var index;
|
|
448
|
+
// Each entry in 'details' shouldn't contain details (duplication) itself
|
|
449
|
+
for (index = 0; index < entry.details.length; index += 1) {
|
|
450
|
+
expect(entry.details[index].details).toBeUndefined();
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it("shouldn't contain duplicated options inside every filter option", function () {
|
|
457
|
+
forEachEntryMatching(
|
|
458
|
+
function (entry) {
|
|
459
|
+
return entry.type === "filter";
|
|
460
|
+
},
|
|
461
|
+
function (entry) {
|
|
462
|
+
var index;
|
|
463
|
+
// Each entry in 'options' shouldn't contain options (duplication) itself
|
|
464
|
+
for (index = 0; index < entry.options.length; index += 1) {
|
|
465
|
+
expect(entry.options[index].options).toBeUndefined();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
});
|
|
470
|
+
});
|
|
435
471
|
});
|
|
436
472
|
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
name: Node CI
|
|
2
|
-
|
|
3
|
-
on: [push]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
build:
|
|
7
|
-
runs-on: ubuntu-latest
|
|
8
|
-
steps:
|
|
9
|
-
- uses: actions/checkout@v2
|
|
10
|
-
- uses: actions/setup-node@v2
|
|
11
|
-
with:
|
|
12
|
-
node-version: '12'
|
|
13
|
-
- name: Install nodes packages
|
|
14
|
-
run: npm ci
|
|
15
|
-
- name: Run tests
|
|
16
|
-
run: npm test
|
|
17
|
-
- name: Measure test coverage
|
|
18
|
-
run: npm run coverage
|
|
19
|
-
- name: Run linter
|
|
20
|
-
run: npm run lint
|
|
21
|
-
- name: Generate documentation
|
|
22
|
-
run: npm run doc
|
|
23
|
-
- name: Build
|
|
24
|
-
run: npm run build --if-present
|
|
25
|
-
- name: Archive code coverage results
|
|
26
|
-
uses: actions/upload-artifact@v2
|
|
27
|
-
with:
|
|
28
|
-
name: code-coverage-report
|
|
29
|
-
path: coverage
|
|
30
|
-
retention-days: 2
|
|
31
|
-
- name: Archive documentation
|
|
32
|
-
uses: actions/upload-artifact@v2
|
|
33
|
-
with:
|
|
34
|
-
name: documentation
|
|
35
|
-
path: docs
|
|
36
|
-
retention-days: 2
|
|
37
|
-
- name: Archive build artifacts
|
|
38
|
-
uses: actions/upload-artifact@v2
|
|
39
|
-
with:
|
|
40
|
-
name: dist-without-markdown
|
|
41
|
-
path: |
|
|
42
|
-
dist
|
|
43
|
-
!dist/**/*.md
|
|
44
|
-
retention-days: 2
|