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
|
@@ -1111,11 +1111,22 @@ datarestructor.Transform = (function () {
|
|
|
1111
1111
|
var describedEntity;
|
|
1112
1112
|
for (index = 0; index < describedEntries.length; index += 1) {
|
|
1113
1113
|
describedEntity = describedEntries[index];
|
|
1114
|
-
result.push(toDescribedField(describedEntity, 0, config));
|
|
1114
|
+
result.push(toDescribedField(describedEntity, {recursionDepth:0, config: config, groupToSkip:""}));
|
|
1115
1115
|
}
|
|
1116
1116
|
return result;
|
|
1117
1117
|
}
|
|
1118
1118
|
|
|
1119
|
+
/**
|
|
1120
|
+
* Describes the context type for the recursive DescribedDataField conversion,
|
|
1121
|
+
* that contains everything that needs to be accessible throughout recursion regardless of the
|
|
1122
|
+
* recursion depth.
|
|
1123
|
+
*
|
|
1124
|
+
* @typedef {Object} module:datarestructor.DescribedFieldRecursionContext
|
|
1125
|
+
* @param {number} recursionDepth current recursion depth
|
|
1126
|
+
* @param {String} groupToSkip name of a group to skip or "" when no group should be skipped.
|
|
1127
|
+
* @param {module:datarestructor.TransformConfig} config configuration for the data transformation
|
|
1128
|
+
*/
|
|
1129
|
+
|
|
1119
1130
|
/**
|
|
1120
1131
|
* Converts a internal described entry to a newly created public described field.
|
|
1121
1132
|
* Since the structure of a described field is hierarchical, this function is called recursively.
|
|
@@ -1123,13 +1134,12 @@ datarestructor.Transform = (function () {
|
|
|
1123
1134
|
* needs to be limited. Therefore, the current recursion depth is taken as second parameter
|
|
1124
1135
|
* and the maximum recursion depth is taken as third parameter.
|
|
1125
1136
|
* @param {module:datarestructor.DescribedEntry} entry the internal entry that will be converted
|
|
1126
|
-
* @param {
|
|
1127
|
-
* @param {module:datarestructor.TransformConfig} config configuration for the data transformation
|
|
1137
|
+
* @param {module:datarestructor.DescribedFieldRecursionContext} recursionContext context contains everything that needs to be accessible throughout the recursion.
|
|
1128
1138
|
* @returns {module:described_field.DescribedDataField}
|
|
1129
1139
|
* @protected
|
|
1130
1140
|
* @memberof module:datarestructor.Transform
|
|
1131
1141
|
*/
|
|
1132
|
-
function toDescribedField(entry,
|
|
1142
|
+
function toDescribedField(entry, recursionContext) {
|
|
1133
1143
|
var field = new described_field.DescribedDataFieldBuilder()
|
|
1134
1144
|
.category(entry.category)
|
|
1135
1145
|
.type(entry.type)
|
|
@@ -1140,37 +1150,70 @@ datarestructor.Transform = (function () {
|
|
|
1140
1150
|
.fieldName(entry.fieldName)
|
|
1141
1151
|
.value(entry.value)
|
|
1142
1152
|
.build();
|
|
1143
|
-
if (recursionDepth > config.maxRecursionDepth) {
|
|
1153
|
+
if (recursionContext.recursionDepth > recursionContext.config.maxRecursionDepth) {
|
|
1144
1154
|
return field;
|
|
1145
1155
|
}
|
|
1156
|
+
var nextRecursionContext = null;
|
|
1157
|
+
var duplicateGroupNameToSkip = "";
|
|
1146
1158
|
var fieldGroups = new described_field.DescribedDataFieldGroup(field);
|
|
1147
|
-
forEachGroupEntry(entry, function (groupName, groupEntry) {
|
|
1148
|
-
if (
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
if (config.debugMode) {
|
|
1152
|
-
console.log(
|
|
1153
|
-
"Removed duplicate field " +
|
|
1154
|
-
groupEntry.fieldName +
|
|
1155
|
-
" with value " +
|
|
1156
|
-
groupEntry.value +
|
|
1157
|
-
" of group " +
|
|
1158
|
-
groupName +
|
|
1159
|
-
" at recursion depth " +
|
|
1160
|
-
recursionDepth
|
|
1161
|
-
);
|
|
1159
|
+
forEachGroupEntry(entry, function (groupName, groupEntry, allGroupEntries) {
|
|
1160
|
+
if (recursionContext.groupToSkip === groupName) {
|
|
1161
|
+
if (recursionContext.config.debugMode) {
|
|
1162
|
+
console.log("Removed duplicate group " + groupName + " at recursion depth " + recursionContext.recursionDepth);
|
|
1162
1163
|
}
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
duplicateGroupNameToSkip = "";
|
|
1167
|
+
if (recursionContext.recursionDepth >= recursionContext.config.removeDuplicationAboveRecursionDepth) {
|
|
1168
|
+
duplicateGroupNameToSkip = arraysEqual(groupEntry[groupName], allGroupEntries, describedFieldEqual)? groupName : "";
|
|
1163
1169
|
}
|
|
1170
|
+
nextRecursionContext = {recursionDepth: recursionContext.recursionDepth + 1, config: recursionContext.config, groupToSkip: duplicateGroupNameToSkip};
|
|
1171
|
+
fieldGroups.addGroupEntry(groupName, toDescribedField(groupEntry, nextRecursionContext));
|
|
1164
1172
|
});
|
|
1165
1173
|
return field;
|
|
1166
1174
|
}
|
|
1167
1175
|
|
|
1176
|
+
function describedFieldEqual(a, b) {
|
|
1177
|
+
return (
|
|
1178
|
+
defaultEmpty(a.category) === defaultEmpty(b.category) &&
|
|
1179
|
+
defaultEmpty(a.type) === defaultEmpty(b.type) &&
|
|
1180
|
+
a.fieldName === b.fieldName &&
|
|
1181
|
+
a.value === b.value
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
function defaultEmpty(value) {
|
|
1186
|
+
return defaultValue(value, "");
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
function defaultValue(value, valueAsDefault) {
|
|
1190
|
+
if (typeof value === "undefined" || !value) {
|
|
1191
|
+
return valueAsDefault;
|
|
1192
|
+
}
|
|
1193
|
+
return value;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// Reference: https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript/16430730
|
|
1197
|
+
// Added "elementEqualFunction" to implement equal object detection.
|
|
1198
|
+
// Arrays are assumed to be sorted. Differently ordered entries are treated as not equal.
|
|
1199
|
+
function arraysEqual(a, b, elementEqualFunction) {
|
|
1200
|
+
if (a === b) return true;
|
|
1201
|
+
if (a == null || b == null) return false;
|
|
1202
|
+
if (a.length !== b.length) return false;
|
|
1203
|
+
|
|
1204
|
+
for (var i = 0; i < a.length; ++i) {
|
|
1205
|
+
if (!elementEqualFunction(a[i], b[i])) return false;
|
|
1206
|
+
}
|
|
1207
|
+
return true;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1168
1210
|
/**
|
|
1169
1211
|
* Takes the full qualified original property name and extracts a simple name out of it.
|
|
1170
1212
|
*
|
|
1171
1213
|
* @callback module:datarestructor.onEntryFoundFunction
|
|
1172
1214
|
* @param {string} groupName name of the group where the entry had been found.
|
|
1173
1215
|
* @param {module:datarestructor.DescribedEntry} foundEntry the found entry itself.
|
|
1216
|
+
* @param {module:datarestructor.DescribedEntry[]} allEntries the array of all entries where the found entry is an element of.
|
|
1174
1217
|
*/
|
|
1175
1218
|
|
|
1176
1219
|
/**
|
|
@@ -1188,13 +1231,12 @@ datarestructor.Transform = (function () {
|
|
|
1188
1231
|
groupName = rootEntry.groupNames[groupIndex];
|
|
1189
1232
|
for (entryIndex = 0; entryIndex < rootEntry[groupName].length; entryIndex += 1) {
|
|
1190
1233
|
entry = rootEntry[groupName][entryIndex];
|
|
1191
|
-
onFoundEntry(groupName, entry);
|
|
1234
|
+
onFoundEntry(groupName, entry, rootEntry[groupName]);
|
|
1192
1235
|
}
|
|
1193
1236
|
}
|
|
1194
1237
|
}
|
|
1195
|
-
|
|
1196
1238
|
return Transform;
|
|
1197
|
-
}
|
|
1239
|
+
}());
|
|
1198
1240
|
|
|
1199
1241
|
/**
|
|
1200
1242
|
* Main fassade for the data restructor as static function(s).
|
|
@@ -1238,7 +1280,7 @@ datarestructor.Restructor.processJsonUsingDescriptions = function(jsonData, desc
|
|
|
1238
1280
|
<br class="clear">
|
|
1239
1281
|
|
|
1240
1282
|
<footer>
|
|
1241
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
1283
|
+
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)
|
|
1242
1284
|
</footer>
|
|
1243
1285
|
|
|
1244
1286
|
<script> prettyPrint(); </script>
|
|
@@ -334,7 +334,7 @@ described_field.DescribedDataFieldGroup = (function () {
|
|
|
334
334
|
<br class="clear">
|
|
335
335
|
|
|
336
336
|
<footer>
|
|
337
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
337
|
+
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)
|
|
338
338
|
</footer>
|
|
339
339
|
|
|
340
340
|
<script> prettyPrint(); </script>
|
package/docs/index.html
CHANGED
|
@@ -43,19 +43,19 @@
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
<section>
|
|
46
|
-
<article><
|
|
46
|
+
<article><h1>data-restructor-js</h1>
|
|
47
|
+
<p><a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License"></a>
|
|
47
48
|
<img src="https://img.shields.io/github/languages/top/JohT/data-restructor-js" alt="Language">
|
|
48
|
-
<img src="https://img.shields.io/badge/
|
|
49
|
+
<img src="https://img.shields.io/badge/branches-94.61%25-brightgreen.svg?style=flat" alt="Branches">
|
|
49
50
|
<img src="https://aleen42.github.io/badges/src/npm.svg" alt="npm">
|
|
50
51
|
<img src="https://aleen42.github.io/badges/src/jasmine.svg" alt="jasmine">
|
|
51
52
|
<img src="https://aleen42.github.io/badges/src/eslint.svg" alt="eslint">
|
|
52
53
|
<img src="https://img.shields.io/github/package-json/dependency-version/JohT/data-restructor-js/dev/jsdoc" alt="JSDoc">
|
|
53
54
|
<img src="https://img.shields.io/github/package-json/dependency-version/JohT/data-restructor-js/dev/nyc" alt="nyc">
|
|
54
|
-
<img src="https://img.shields.io/github/package-json/dependency-version/JohT/data-restructor-js/dev/parcel
|
|
55
|
-
<h1>data-restructor-js</h1>
|
|
55
|
+
<img src="https://img.shields.io/github/package-json/dependency-version/JohT/data-restructor-js/dev/parcel" alt="parcel-bundler"></p>
|
|
56
56
|
<p>When parsing JSON on client-side, the structure of it attracts most of our attention.<br>
|
|
57
57
|
If the structure evolves over time, it leads to recurring changes in the code that depends on it.</p>
|
|
58
|
-
<h2>Features
|
|
58
|
+
<h2>Features</h2>
|
|
59
59
|
<ul>
|
|
60
60
|
<li>Adapter that takes e.g. parsed JSON and transforms it into a uniform structure</li>
|
|
61
61
|
<li>Multiple transformation steps including flattening, removing duplicates, grouping, ...</li>
|
|
@@ -71,7 +71,7 @@ If the structure evolves over time, it leads to recurring changes in the code th
|
|
|
71
71
|
</ul>
|
|
72
72
|
<h2>Quickstart</h2>
|
|
73
73
|
<p>Use the following command to install the library using npm:</p>
|
|
74
|
-
<pre class="prettyprint source"><code>npm install data-restructor
|
|
74
|
+
<pre class="prettyprint source lang-shell"><code>npm install data-restructor
|
|
75
75
|
</code></pre>
|
|
76
76
|
<p>Alternatively, the sources can be found inside the
|
|
77
77
|
<a href="https://github.com/JohT/data-restructor-js/tree/master/src/">source folder</a>:</p>
|
|
@@ -178,7 +178,7 @@ function detailsDescription() {
|
|
|
178
178
|
}
|
|
179
179
|
</code></pre>
|
|
180
180
|
<h3>Output Java Object</h3>
|
|
181
|
-
<p>An Javascript object with mainly this structure (see <a href="#
|
|
181
|
+
<p>An Javascript object with mainly this structure (see <a href="#describedentry">DescribedEntry</a> for more details) and content is returned, when the function <code>restructureJson</code> from above is called:</p>
|
|
182
182
|
<pre class="prettyprint source lang-yaml"><code>category: "account"
|
|
183
183
|
displayName: "Accountnumber"
|
|
184
184
|
fieldName: "accountnumber"
|
|
@@ -221,7 +221,7 @@ details:
|
|
|
221
221
|
fieldName: "tags_comma_separated_values"
|
|
222
222
|
value: "active, online"
|
|
223
223
|
</code></pre>
|
|
224
|
-
<h2>Transformation Steps
|
|
224
|
+
<h2>Transformation Steps</h2>
|
|
225
225
|
<h3>1. Flatten hierarchical data object</h3>
|
|
226
226
|
<p>The input data object, e.g. parsed from JSON, is converted to an array of point separated property names and their values.
|
|
227
227
|
For example this structure...</p>
|
|
@@ -245,7 +245,7 @@ For example this structure...</p>
|
|
|
245
245
|
}
|
|
246
246
|
</code></pre>
|
|
247
247
|
<p>...is flattened to...</p>
|
|
248
|
-
<pre class="prettyprint source"><code>responses[0].hits.total.value=1
|
|
248
|
+
<pre class="prettyprint source lang-javascript"><code>responses[0].hits.total.value=1
|
|
249
249
|
responses[0].hits.hits[0]._source.accountnumber=123
|
|
250
250
|
</code></pre>
|
|
251
251
|
<h3>2. Add array value properties ending with "_comma_separated_values"</h3>
|
|
@@ -255,12 +255,12 @@ that contains the values in a comma separated way.
|
|
|
255
255
|
This newly created property gets the name of the array property followed by "_comma_separated_values"
|
|
256
256
|
and is inserted right after the single array values.</p>
|
|
257
257
|
<p>For example these lines...</p>
|
|
258
|
-
<pre class="prettyprint source"><code>responses[0].hits.total.value=1
|
|
258
|
+
<pre class="prettyprint source lang-javascript"><code>responses[0].hits.total.value=1
|
|
259
259
|
responses[0].hits.hits[0]._source.tags[0]=active
|
|
260
260
|
responses[0].hits.hits[0]._source.tags[1]=online
|
|
261
261
|
</code></pre>
|
|
262
262
|
<p>...will lead to an additional property that looks like this...</p>
|
|
263
|
-
<pre class="prettyprint source"><code>responses[0].hits.hits[0]._source.tags_comma_separated_values=active, online
|
|
263
|
+
<pre class="prettyprint source lang-javascript"><code>responses[0].hits.hits[0]._source.tags_comma_separated_values=active, online
|
|
264
264
|
</code></pre>
|
|
265
265
|
<h3>3. Attach description to matching properties</h3>
|
|
266
266
|
<p>For every given description, all properties are searched for matches.
|
|
@@ -268,45 +268,50 @@ If a description matches a property, the description gets attached to it.
|
|
|
268
268
|
This can be used to categorize and filter properties.
|
|
269
269
|
The description builder accepts these ways to configure property matching:</p>
|
|
270
270
|
<ul>
|
|
271
|
-
<li>
|
|
271
|
+
<li>
|
|
272
|
+
<p>Equal Mode (default):<br>
|
|
272
273
|
The property name needs to match the described pattern exactly. It is not needed to set equal mode.
|
|
273
274
|
The field name will be (by default) taken from the right most (after the last separator <code>.</code>) element of the property name.
|
|
274
275
|
In the example below the field name will be "accountnumber".
|
|
275
|
-
Example
|
|
276
|
+
Example:</p>
|
|
277
|
+
<pre class="prettyprint source lang-javascript"><code>new datarestructor.PropertyStructureDescriptionBuilder()
|
|
276
278
|
.propertyPatternEqualMode()
|
|
277
279
|
.propertyPattern("responses.hits.hits._source.accountnumber")
|
|
278
280
|
...
|
|
279
281
|
</code></pre>
|
|
280
282
|
</li>
|
|
281
|
-
<li>
|
|
283
|
+
<li>
|
|
284
|
+
<p>Pattern Mode:<br>
|
|
282
285
|
The property name needs to start with the described pattern.
|
|
283
286
|
The pattern may contain variables inside double curly brackets.<br>
|
|
284
287
|
The variable <code>{{fieldName}}</code> is a special case which describes from where the field name should be taken.
|
|
285
288
|
If <code>{{fieldName}}</code> is not specified, the field name will be taken from the right most (after the last separator <code>.</code>) element of the property name, which is the same behavior as in "Equal Mode".
|
|
286
289
|
This mode needs to set using <code>propertyPatternTemplateMode</code>, since the default mode is <code>propertyPatternEqualMode</code>.
|
|
287
|
-
Example
|
|
290
|
+
Example:</p>
|
|
291
|
+
<pre class="prettyprint source lang-javascript"><code>new datarestructor.PropertyStructureDescriptionBuilder()
|
|
288
292
|
.propertyPatternTemplateMode()
|
|
289
293
|
.propertyPattern("responses.hits.hits._source.{{fieldName}}")
|
|
290
294
|
...
|
|
291
295
|
</code></pre>
|
|
292
296
|
</li>
|
|
293
|
-
<li>
|
|
297
|
+
<li>
|
|
298
|
+
<p>Index Matching (Optional):<br>
|
|
294
299
|
If the source data is structured in an top level array and all property names look pretty much the same
|
|
295
300
|
it may be needed to describe data based on the array index.
|
|
296
301
|
The index of an property is taken out of its array qualifiers.<br>
|
|
297
302
|
For example, the property name <code>responses[0].hits.hits[1]._source.tags[2]</code> has the index <code>0.1.2</code>.<br>
|
|
298
303
|
Index Matching can be combined with property name matching.
|
|
299
|
-
This example restricts the description to the first top level array
|
|
304
|
+
This example restricts the description to the first top level array:</p>
|
|
305
|
+
<pre class="prettyprint source lang-javascript"><code>new datarestructor.PropertyStructureDescriptionBuilder()
|
|
300
306
|
.indexStartsWith("0.")
|
|
301
307
|
...
|
|
302
308
|
</code></pre>
|
|
303
309
|
</li>
|
|
304
310
|
</ul>
|
|
305
|
-
<h3>4. Removing duplicates (deduplication)
|
|
311
|
+
<h3>4. Removing duplicates (deduplication)</h3>
|
|
306
312
|
<p>To remove duplicate properties or to override properties with other ones when they exist,
|
|
307
313
|
a <code>deduplicationPattern</code> can be defined.<br/><br/>
|
|
308
|
-
Variables (listed below) are put into double curly brackets and will be replaced with the contents
|
|
309
|
-
of the description and the matching property.<br>
|
|
314
|
+
Variables (listed below) are put into double curly brackets and will be replaced with the contents of the description and the matching property.<br>
|
|
310
315
|
If there are two entries with the same resolved <code>deduplicationPattern</code> (=<code>_identifier.deduplicationId</code>),
|
|
311
316
|
the second one will override the first (the first one will be removed).
|
|
312
317
|
Example:</p>
|
|
@@ -314,7 +319,7 @@ Example:</p>
|
|
|
314
319
|
.deduplicationPattern("{{category}}--{{type}}--{{index[0]}}--{{index[1]}}--{{fieldName}}")
|
|
315
320
|
...
|
|
316
321
|
</code></pre>
|
|
317
|
-
<h3>5. Grouping
|
|
322
|
+
<h3>5. Grouping</h3>
|
|
318
323
|
<p>Since data had been flattened in the step 1., it is structured as a list of property names and their values.
|
|
319
324
|
This non-hierarchical structure is ideal to add further properties, attach descriptions and remove duplicates.
|
|
320
325
|
After all, a fully flat structure might not be suitable to display overviews/details or to collect options. <br/><br/>
|
|
@@ -330,7 +335,7 @@ same group will be put into. Example:</p>
|
|
|
330
335
|
.groupPattern("{{category}}--{{type}}--{{index[0]}}--{{index[1]}}")
|
|
331
336
|
...
|
|
332
337
|
</code></pre>
|
|
333
|
-
<h3>6. Moving groups (destination group)
|
|
338
|
+
<h3>6. Moving groups (destination group)</h3>
|
|
334
339
|
<p>After grouping in step 5., every property containing a group and the remaining non-grouped properties
|
|
335
340
|
are listed one after another. To organize them further, a group can be moved beneath another (destination) group. <br/><br/>
|
|
336
341
|
The <code>groupDestinationPattern</code> contains the pattern of the group to where the own group should be moved.
|
|
@@ -351,9 +356,9 @@ var detailsDescription = new datarestructor.PropertyStructureDescriptionBuilder(
|
|
|
351
356
|
.groupDestinationName("details")
|
|
352
357
|
...
|
|
353
358
|
</code></pre>
|
|
354
|
-
<h3>7. Convert data into an array of DescribedFields
|
|
355
|
-
<p>The result is finally converted into an array of <a href="#
|
|
356
|
-
<h2>Types, fields, variables
|
|
359
|
+
<h3>7. Convert data into an array of DescribedFields</h3>
|
|
360
|
+
<p>The result is finally converted into an array of <a href="#describeddatafield">DescribedDataField</a>s.</p>
|
|
361
|
+
<h2>Types, fields, variables</h2>
|
|
357
362
|
<p>This section lists the types and their fields in detail (mostly taken from jsdoc).
|
|
358
363
|
Every field can be used as variable in double curly brackets inside pattern properties.
|
|
359
364
|
Additionally, single elements of the index can be used by specifying the index position e.g. <code>{{index[0]}}</code> (first), <code>{{index[1]}}</code> (second),...</p>
|
|
@@ -363,34 +368,34 @@ Additionally, single elements of the index can be used by specifying the index p
|
|
|
363
368
|
<li><strong>category</strong> - name of the category. Default = "". Could contain a symbol character or a short domain name. (e.g. "city")</li>
|
|
364
369
|
<li><strong>abbreviation</strong> - ""(default). One optional character, a symbol character or a short abbreviation of the category.</li>
|
|
365
370
|
<li><strong>image</strong> - ""(default). One optional path to an image resource.</li>
|
|
366
|
-
<li><strong>propertyPatternTemplateMode</strong> - boolean "false"(default): property name needs to be equal to the pattern. "true" allows variables like
|
|
367
|
-
<li><strong>propertyPattern</strong> - property name pattern (without array indices) to match. A pattern may contain variables in double curly brackets {{variable}}. See also: <a href="#public-fields">variables</a>, <a href="#public-functions">further details</a></li>
|
|
371
|
+
<li><strong>propertyPatternTemplateMode</strong> - boolean "false"(default): property name needs to be equal to the pattern. "true" allows variables like <code>{{fieldname}}</code> inside the pattern.</li>
|
|
372
|
+
<li><strong>propertyPattern</strong> - property name pattern (without array indices) to match. A pattern may contain variables in double curly brackets {{variable}}. See also: <a href="#describeddatafield-public-fields">variables</a>, <a href="#describeddatafield-public-functions">further details</a></li>
|
|
368
373
|
<li><strong>indexStartsWith</strong> - ""(default) matches all ids. String that needs to match the beginning of the id. E.g. "1." will match id="1.3.4" but not "0.1.2".</li>
|
|
369
374
|
<li><strong>groupName</strong> - name of the property, that contains grouped entries. Default="group".</li>
|
|
370
|
-
<li><strong>groupPattern</strong> - Pattern that describes how to group entries. "groupName" defines the name of this group. A pattern may contain variables in double curly brackets {{variable}}. See also: <a href="#public-fields">variables</a>, <a href="#public-functions">further details</a></li>
|
|
371
|
-
<li><strong>groupDestinationPattern</strong> - Pattern that describes where the group should be moved to. Default=""=Group will not be moved. A pattern may contain variables in double curly brackets {{variable}}. See also: <a href="#public-fields">variables</a>, <a href="#public-functions">further details</a></li>
|
|
375
|
+
<li><strong>groupPattern</strong> - Pattern that describes how to group entries. "groupName" defines the name of this group. A pattern may contain variables in double curly brackets {{variable}}. See also: <a href="#describeddatafield-public-fields">variables</a>, <a href="#describeddatafield-public-functions">further details</a></li>
|
|
376
|
+
<li><strong>groupDestinationPattern</strong> - Pattern that describes where the group should be moved to. Default=""=Group will not be moved. A pattern may contain variables in double curly brackets {{variable}}. See also: <a href="#describeddatafield-public-fields">variables</a>, <a href="#describeddatafield-public-functions">further details</a></li>
|
|
372
377
|
<li><strong>groupDestinationName</strong> - (default=groupName) Name of the group when it had been moved to the destination.</li>
|
|
373
|
-
<li><strong>deduplicationPattern</strong> - Pattern to use to remove duplicate entries. A pattern may contain variables in double curly brackets {{variable}}. See also: <a href="#public-fields">variables</a>, <a href="#public-functions">further details</a></li>
|
|
378
|
+
<li><strong>deduplicationPattern</strong> - Pattern to use to remove duplicate entries. A pattern may contain variables in double curly brackets {{variable}}. See also: <a href="#describeddatafield-public-fields">variables</a>, <a href="#describeddatafield-public-functions">further details</a></li>
|
|
374
379
|
</ul>
|
|
375
380
|
<h3>DescribedDataField</h3>
|
|
376
381
|
<p>This is the data structure of a single output element representing a field.
|
|
377
382
|
Beside the properties described below, the described data field can also contain
|
|
378
383
|
custom properties containing groups (arrays) of sub fields of type DescribedDataField.</p>
|
|
379
|
-
<p>Before version 3.0.0 this structure was named <a href="#
|
|
380
|
-
Since 3.0.0 and above, <a href="#
|
|
381
|
-
<h4>Public
|
|
384
|
+
<p>Before version 3.0.0 this structure was named <a href="#describedentry">DescribedEntry</a> and also contained internal fields.<br>
|
|
385
|
+
Since 3.0.0 and above, <a href="#describedentry">DescribedEntry</a> is only used internally and is not public any more.</p>
|
|
386
|
+
<h4>DescribedDataField Public Fields</h4>
|
|
382
387
|
<ul>
|
|
383
388
|
<li><strong>category</strong> - category of the result from the PropertyStructureDescription using a short name or e.g. a symbol character</li>
|
|
384
389
|
<li><strong>type</strong> - type of the result from PropertyStructureDescription</li>
|
|
385
390
|
<li><strong>abbreviation</strong> - one optional character, a symbol character or a short abbreviation of the category</li>
|
|
386
391
|
<li><strong>image</strong> - one optional path to an image resource</li>
|
|
387
392
|
<li><strong>index</strong> - contains an array of numbers representing the hierarchical index for list entries (and their sub lists ...). Example: <code>"responses[2].hits.hits[4]._source.name"</code> will have an index of [2,4].</li>
|
|
388
|
-
<li><strong>groupNames</strong> - contains an array of String names. Every name represents a group that had been dynamically added as property. Groups should be added using <a href="#
|
|
393
|
+
<li><strong>groupNames</strong> - contains an array of String names. Every name represents a group that had been dynamically added as property. Groups should be added using <a href="#describeddatafieldgroup">DescribedDataFieldGroup</a>, which will also update the group names.</li>
|
|
389
394
|
<li><strong>displayName</strong> - display name extracted from the point separated hierarchical property name, e.g. "Name"</li>
|
|
390
395
|
<li><strong>fieldName</strong> - field name extracted from the point separated hierarchical property name, e.g. "name"</li>
|
|
391
396
|
<li><strong>value</strong> - content of the field</li>
|
|
392
397
|
</ul>
|
|
393
|
-
<h4>Public
|
|
398
|
+
<h4>DescribedDataField Public Functions</h4>
|
|
394
399
|
<p>Since version 3.0.0 and above, there are no functions any more.</p>
|
|
395
400
|
<h4>Described groups</h4>
|
|
396
401
|
<ul>
|
|
@@ -398,9 +403,9 @@ Since 3.0.0 and above, <a href="#DescribedEntry">DescribedEntry</a> is only used
|
|
|
398
403
|
<li><strong>"names of moved groups"</strong> as described in PropertyStructureDescription of the group that had been moved</li>
|
|
399
404
|
</ul>
|
|
400
405
|
<h3>DescribedDataFieldGroup</h3>
|
|
401
|
-
<p>This helper was added with version 3.0.0. It adds groups to <a href="#
|
|
402
|
-
These groups are dynamically added properties that contain an array of sub fields also of type <a href="#
|
|
403
|
-
<h4>Public
|
|
406
|
+
<p>This helper was added with version 3.0.0. It adds groups to <a href="#describeddatafield">DescribedDataField</a>s.
|
|
407
|
+
These groups are dynamically added properties that contain an array of sub fields also of type <a href="#describeddatafield">DescribedDataField</a>.</p>
|
|
408
|
+
<h4>DescribedDataFieldGroup Public Functions</h4>
|
|
404
409
|
<ul>
|
|
405
410
|
<li><strong>addGroupEntry(groupName, entry)</strong> Adds an entry to the given group. If the group does not exist, it will be created and added to the "groupNames".</li>
|
|
406
411
|
<li><strong>addGroupEntries(groupName, entries)</strong> Adds an array of entries to the given group. If the group does not exist, it will be created and added to the "groupNames".</li>
|
|
@@ -411,7 +416,7 @@ It is documented here for sake of completeness and for maintenance purposes.
|
|
|
411
416
|
See JSDoc for a more comprehensive reference.</p>
|
|
412
417
|
<h4>Properties</h4>
|
|
413
418
|
<ul>
|
|
414
|
-
<li><strong>describedField</strong> - contains the <a href="#
|
|
419
|
+
<li><strong>describedField</strong> - contains the <a href="#describeddatafield">DescribedDataField</a></li>
|
|
415
420
|
<li><strong>isMatchingIndex</strong> - true, if _identifier.index matches the described "indexStartsWith"</li>
|
|
416
421
|
<li><strong>_identifier</strong> - internal structure for identifier. Avoid using it outside since it may change.</li>
|
|
417
422
|
<li><strong>_identifier.index</strong> - array indices in hierarchical order separated by points, e.g. "0.0"</li>
|
|
@@ -433,12 +438,12 @@ var template = "{{type}}-{{category}}";
|
|
|
433
438
|
var resolvedString = resolver.resolveTemplate(template);
|
|
434
439
|
//resolvedString will contain "MyType-MyCategory"
|
|
435
440
|
</code></pre>
|
|
436
|
-
<h4>Public
|
|
441
|
+
<h4>Template Resolver Public Functions</h4>
|
|
437
442
|
<ul>
|
|
438
443
|
<li><strong>resolveTemplate</strong> - resolves the given template string. The template may contain variables in double curly brackets:
|
|
439
444
|
<ul>
|
|
440
|
-
<li>All <a href="#public-fields">public fields</a> can be used as variables, e.g. <code>"{{fieldName}}"</code>, <code>"{{displayName}}"</code>, <code>"{{value}}"</code>.</li>
|
|
441
|
-
<li>Described groups that contain an array of <a href="#
|
|
445
|
+
<li>All <a href="#describeddatafield-public-fields">public fields</a> can be used as variables, e.g. <code>"{{fieldName}}"</code>, <code>"{{displayName}}"</code>, <code>"{{value}}"</code>.</li>
|
|
446
|
+
<li>Described groups that contain an array of <a href="#describeddatafield">described entries</a> can also be used, e.g. <code>"{{summaries[0].value}}"</code>.</li>
|
|
442
447
|
<li>Parts of the index can be inserted by using e.g. <code>"{{index[1]}}"</code>.</li>
|
|
443
448
|
<li>Besides the meta data, a described field can be used directly by its "fieldName", e.g. <code>"{{customernumber}}"</code> will be replaced by <code>123</code>, if the structure contains <code>fieldname="customernumber", value="123"</code>. This also applies to sub groups, e.g. <code>"{{details.customernumber}}"</code> will be replaced by <code>321</code>, if the structure contains <code>details[4].fieldname="customernumber", details[4].value="321"</code>.</li>
|
|
444
449
|
</ul>
|
|
@@ -449,7 +454,7 @@ var resolvedString = resolver.resolveTemplate(template);
|
|
|
449
454
|
<p>The restructured data is by nature hierarchical and may contain cyclic data references. Fields may contain groups of fields that may contain groups of fields....
|
|
450
455
|
Since JSON can't be generated out of objects with cyclic references, sub-structures are expressed by copies.
|
|
451
456
|
That leads to recursion and duplication, that need to be limited. This can be configured here.</p>
|
|
452
|
-
<h4>Properties</h4>
|
|
457
|
+
<h4>TransformConfig Properties</h4>
|
|
453
458
|
<ul>
|
|
454
459
|
<li><strong>debugMode</strong> boolean value, that enables/disables detailed logging</li>
|
|
455
460
|
<li><strong>maxRecursionDepth</strong> numeric value that defines the maximum recursion depth</li>
|
|
@@ -807,7 +812,7 @@ That leads to recursion and duplication, that need to be limited. This can be co
|
|
|
807
812
|
<br class="clear">
|
|
808
813
|
|
|
809
814
|
<footer>
|
|
810
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
815
|
+
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)
|
|
811
816
|
</footer>
|
|
812
817
|
|
|
813
818
|
<script> prettyPrint(); </script>
|
|
@@ -905,7 +905,7 @@ This is the public version of the internal variable _identifier.index, which con
|
|
|
905
905
|
<br class="clear">
|
|
906
906
|
|
|
907
907
|
<footer>
|
|
908
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
908
|
+
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)
|
|
909
909
|
</footer>
|
|
910
910
|
|
|
911
911
|
<script> prettyPrint(); </script>
|
|
@@ -2948,7 +2948,7 @@ starts with the "propertyPattern".</p>
|
|
|
2948
2948
|
<br class="clear">
|
|
2949
2949
|
|
|
2950
2950
|
<footer>
|
|
2951
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
2951
|
+
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)
|
|
2952
2952
|
</footer>
|
|
2953
2953
|
|
|
2954
2954
|
<script> prettyPrint(); </script>
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
|
|
74
74
|
<dt class="tag-source">Source:</dt>
|
|
75
75
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
76
|
-
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#
|
|
76
|
+
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#line1213">line 1213</a>
|
|
77
77
|
</li></ul></dd>
|
|
78
78
|
|
|
79
79
|
|
|
@@ -269,7 +269,7 @@ var result = datarestructor.Restructor.processJsonUsingDescriptions(jsonData, al
|
|
|
269
269
|
|
|
270
270
|
<dt class="tag-source">Source:</dt>
|
|
271
271
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
272
|
-
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#
|
|
272
|
+
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#line1233">line 1233</a>
|
|
273
273
|
</li></ul></dd>
|
|
274
274
|
|
|
275
275
|
|
|
@@ -339,7 +339,7 @@ var result = datarestructor.Restructor.processJsonUsingDescriptions(jsonData, al
|
|
|
339
339
|
<br class="clear">
|
|
340
340
|
|
|
341
341
|
<footer>
|
|
342
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
342
|
+
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)
|
|
343
343
|
</footer>
|
|
344
344
|
|
|
345
345
|
<script> prettyPrint(); </script>
|
|
@@ -1354,7 +1354,7 @@ with the group name and the entry itself as parameters.</p>
|
|
|
1354
1354
|
|
|
1355
1355
|
<dt class="tag-source">Source:</dt>
|
|
1356
1356
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
1357
|
-
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#
|
|
1357
|
+
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#line1199">line 1199</a>
|
|
1358
1358
|
</li></ul></dd>
|
|
1359
1359
|
|
|
1360
1360
|
|
|
@@ -2131,7 +2131,7 @@ if they have the same id.</p>
|
|
|
2131
2131
|
|
|
2132
2132
|
|
|
2133
2133
|
|
|
2134
|
-
<h4 class="name" id=".toDescribedField"><span class="type-signature">(protected, static) </span>toDescribedField<span class="signature">(entry,
|
|
2134
|
+
<h4 class="name" id=".toDescribedField"><span class="type-signature">(protected, static) </span>toDescribedField<span class="signature">(entry, recursionContext)</span><span class="type-signature"> → {<a href="module-described_field.html#.DescribedDataField">module:described_field.DescribedDataField</a>}</span></h4>
|
|
2135
2135
|
|
|
2136
2136
|
|
|
2137
2137
|
|
|
@@ -2202,36 +2202,13 @@ and the maximum recursion depth is taken as third parameter.</p>
|
|
|
2202
2202
|
|
|
2203
2203
|
<tr>
|
|
2204
2204
|
|
|
2205
|
-
<td class="name"><code>
|
|
2205
|
+
<td class="name"><code>recursionContext</code></td>
|
|
2206
2206
|
|
|
2207
2207
|
|
|
2208
2208
|
<td class="type">
|
|
2209
2209
|
|
|
2210
2210
|
|
|
2211
|
-
<span class="param-type">
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
</td>
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
<td class="description last"><p>current hierarchy recursion depth</p></td>
|
|
2222
|
-
</tr>
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
<tr>
|
|
2227
|
-
|
|
2228
|
-
<td class="name"><code>config</code></td>
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
<td class="type">
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
<span class="param-type"><a href="module-datarestructor.html#.TransformConfig">module:datarestructor.TransformConfig</a></span>
|
|
2211
|
+
<span class="param-type"><a href="module-datarestructor.html#.DescribedFieldRecursionContext">module:datarestructor.DescribedFieldRecursionContext</a></span>
|
|
2235
2212
|
|
|
2236
2213
|
|
|
2237
2214
|
|
|
@@ -2241,7 +2218,7 @@ and the maximum recursion depth is taken as third parameter.</p>
|
|
|
2241
2218
|
|
|
2242
2219
|
|
|
2243
2220
|
|
|
2244
|
-
<td class="description last"><p>
|
|
2221
|
+
<td class="description last"><p>context contains everything that needs to be accessible throughout the recursion.</p></td>
|
|
2245
2222
|
</tr>
|
|
2246
2223
|
|
|
2247
2224
|
|
|
@@ -2282,7 +2259,7 @@ and the maximum recursion depth is taken as third parameter.</p>
|
|
|
2282
2259
|
|
|
2283
2260
|
<dt class="tag-source">Source:</dt>
|
|
2284
2261
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
2285
|
-
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#
|
|
2262
|
+
<a href="datarestructor.js.html">datarestructor.js</a>, <a href="datarestructor.js.html#line1114">line 1114</a>
|
|
2286
2263
|
</li></ul></dd>
|
|
2287
2264
|
|
|
2288
2265
|
|
|
@@ -3117,7 +3094,7 @@ recursion depth, above which further duplication won't be used and should be rem
|
|
|
3117
3094
|
<br class="clear">
|
|
3118
3095
|
|
|
3119
3096
|
<footer>
|
|
3120
|
-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.
|
|
3097
|
+
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)
|
|
3121
3098
|
</footer>
|
|
3122
3099
|
|
|
3123
3100
|
<script> prettyPrint(); </script>
|