data-restructor 3.4.1 → 3.4.2

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.
Files changed (39) hide show
  1. package/.github/workflows/codeql-analysis.yml +1 -1
  2. package/.github/workflows/continuous-integration.yaml +10 -1
  3. package/CHANGELOG.md +23 -1
  4. package/coverage/datarestructor.js.html +133 -133
  5. package/coverage/describedfield.js.html +45 -45
  6. package/coverage/index.html +1 -1
  7. package/coverage/templateResolver.js.html +26 -26
  8. package/devdist/datarestructor-ie.js +12 -12
  9. package/devdist/datarestructor.js +6 -6
  10. package/devdist/describedfield-ie.js +2 -2
  11. package/devdist/templateResolver-ie.js +6 -6
  12. package/devdist/templateResolver.js +2 -2
  13. package/dist/datarestructor-ie.js +693 -1
  14. package/dist/datarestructor-ie.js.map +1 -1
  15. package/dist/datarestructor.js +687 -1
  16. package/dist/datarestructor.js.map +1 -1
  17. package/dist/describedfield-ie.js +142 -1
  18. package/dist/describedfield-ie.js.map +1 -1
  19. package/dist/describedfield.js +142 -1
  20. package/dist/describedfield.js.map +1 -1
  21. package/dist/templateResolver-ie.js +82 -1
  22. package/dist/templateResolver-ie.js.map +1 -1
  23. package/dist/templateResolver.js +76 -1
  24. package/dist/templateResolver.js.map +1 -1
  25. package/docs/datarestructor.js.html +1 -1
  26. package/docs/describedfield.js.html +1 -1
  27. package/docs/index.html +1 -1
  28. package/docs/module-datarestructor.DescribedEntryCreator.html +1 -1
  29. package/docs/module-datarestructor.PropertyStructureDescriptionBuilder.html +1 -1
  30. package/docs/module-datarestructor.Restructor.html +1 -1
  31. package/docs/module-datarestructor.Transform.html +1 -1
  32. package/docs/module-datarestructor.html +1 -1
  33. package/docs/module-described_field.DescribedDataFieldBuilder.html +1 -1
  34. package/docs/module-described_field.DescribedDataFieldGroup.html +1 -1
  35. package/docs/module-described_field.html +1 -1
  36. package/docs/module-template_resolver.Resolver.html +1 -1
  37. package/docs/module-template_resolver.html +1 -1
  38. package/docs/templateResolver.js.html +1 -1
  39. package/package.json +7 -7
@@ -1,2 +1,688 @@
1
- var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},t={},i={},r=e.parcelRequirec1f2;null==r&&((r=function(e){if(e in t)return t[e].exports;if(e in i){var r=i[e];delete i[e];var n={id:e,exports:{}};return t[e]=n,r.call(n.exports,n,n.exports),n.exports}var o=new Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,t){i[e]=t},e.parcelRequirec1f2=r),r.register("7HmuL",(function(e,t){"use strict";var i=i||{};(i.exports={}).flattenToArray=function(e,t){var i=[];return("number"!=typeof t||t<1)&&(t=20),function e(r,n,o){if(!(o>t||"function"==typeof r))if(Object(r)!==r)i.push({name:n,value:r});else if(Array.isArray(r)){var a,s=r.length;for(a=0;a<s;a+=1)e(r[a],n+"["+a+"]",o+1);0===s&&(i[n]=[],i.push({name:n,value:""}))}else{var u,c=!0;for(u in r)c=!1,e(r[u],n?n+"."+u:u,o+1);c&&n&&i.push({name:n,value:""})}}(e,"",0),i}})),r.register("8ZIyB",(function(e,t){"use strict";var i=n(i);function n(e){return e||{}}var o=i.exports={};o.internalCreateIfNotExists=n;var a=a||r("7HmuL");o.Resolver=function(){var e=new RegExp("\\[\\d+\\]","gi");function t(t){var i=t.lastIndexOf("."),r=t;i>0&&(r=t.substr(i+1));var n="";i>0&&(n=t.substr(0,i+1));var o=n.replace(e,"");return{group:n,groupWithoutArrayIndices:o,name:r}}function i(e,t,i){var r,n;for(r=0;r<e.length;r+=1)n=e[r],"function"==typeof i&&i(n.name)&&(t[n.name]=n.value);return t}return function(e){this.sourceDataObject=e,this.resolveTemplate=function(e){return this.replaceResolvableFields(e,function(e){var i,r,n,o,a=Object.keys(e);for(i=0;i<a.length;i+=1)o=e[r=a[i]],"fieldName"===(n=t(r)).name&&"fieldName"!==o&&(e[n.groupWithoutArrayIndices+o]=e[n.group+"value"]);return e}(this.resolvableFieldsOfAll(this.sourceDataObject)))},this.resolvableFieldsOfAll=function(){var e,t={},r=function(e){return 0!==e.indexOf("_")&&e.indexOf("._")<0};for(e=0;e<arguments.length;e+=1)i(a.flattenToArray(arguments[e],3),t,r);return t},this.replaceResolvableFields=function(e,t){var i=e,r=Object.keys(t),n=0,o="",a="";for(n=0;n<r.length;n+=1)a=t[o=r[n]],i=i.replace("{{"+o+"}}",a);return i}}}()})),r.register("d63jw",(function(e,t){"use strict";var i=r(i);function r(e){return e||{}}var n=i.exports={};n.internalCreateIfNotExists=r,n.DescribedDataFieldBuilder=function(){function e(e,t){return function(e){return"string"==typeof e&&null!==e&&""!==e}(e)?e:t}function t(e,t){return null==e?t:e}return function(){this.describedField={category:"",type:"",abbreviation:"",image:"",index:[],groupNames:[],displayName:"",fieldName:"",value:""},this.fromDescribedDataField=function(e){return this.category(e.category),this.type(e.type),this.abbreviation(e.abbreviation),this.image(e.image),this.index(e.index),this.groupNames(e.groupNames),this.displayName(e.displayName),this.fieldName(e.fieldName),this.value(e.value),this},this.category=function(t){return this.describedField.category=e(t,""),this},this.type=function(t){return this.describedField.type=e(t,""),this},this.abbreviation=function(t){return this.describedField.abbreviation=e(t,""),this},this.image=function(t){return this.describedField.image=e(t,""),this},this.index=function(e){return this.describedField.index=t(e,[]),this},this.groupNames=function(e){return this.describedField.groupNames=t(e,[]),this},this.displayName=function(t){return this.describedField.displayName=e(t,""),this},this.fieldName=function(t){return this.describedField.fieldName=e(t,""),this},this.value=function(e){return this.describedField.value=e,this},this.build=function(){return this.describedField}}}(),n.copyWithoutGroups=function(e){return(new n.DescribedDataFieldBuilder).fromDescribedDataField(e).groupNames([]).build()},n.DescribedDataFieldGroup=function(e){this.dataField=e,this.addGroupEntry=function(e,t){return this.addGroupEntries(e,[t]),this},this.addGroupEntries=function(e,t){if(!e||0===e.length)return this;if(!t||0===t.length)return this;var i,r;for(void 0===this.dataField[e]&&(this.dataField.groupNames.push(e),this.dataField[e]=[]),i=0;i<t.length;i+=1)r=t[i],this.dataField[e].push(r);return this}}}));var n=o(n);function o(e){return e||{}}var a=n.exports={};a.internalCreateIfNotExists=o;var s=s||r("7HmuL"),u=u||r("8ZIyB"),c=c||r("d63jw");a.PropertyStructureDescriptionBuilder=function(){"use strict";function e(e,r){if(o(e))return function(){return e};if(r.propertyPatternTemplateMode){var n=r.propertyPattern;return a=n,function(e){var r=i(a,"{{fieldName}}").exec(e);return r&&""!=r[1]?r[1]:t(e)}}var a;return function(e){return t(e)}}function t(e){var t=new RegExp("(\\w+)$","gi"),i=e.match(t);return null!=i?i[0]:e}function i(e,t){var i=r(e);return"string"==typeof t&&(t=r(t)),i="^"+(i=i.replace(t,"([-\\w]+)")),new RegExp(i,"i")}function r(e){var t=new RegExp("([^-\\w])","gi");return e.replace(t,"\\$1")}function n(e,t){return o(e)?e:t}function o(e){return"string"==typeof e&&null!=e&&""!=e}return function(){this.description={type:"",category:"",abbreviation:"",image:"",propertyPatternTemplateMode:!1,propertyPattern:"",indexStartsWith:"",groupName:"group",groupPattern:"",groupDestinationPattern:"",groupDestinationName:null,deduplicationPattern:"",getDisplayNameForPropertyName:null,getFieldNameForPropertyName:null,matchesPropertyName:null},this.type=function(e){return this.description.type=n(e,""),this},this.category=function(e){return this.description.category=n(e,""),this},this.abbreviation=function(e){return this.description.abbreviation=n(e,""),this},this.image=function(e){return this.description.image=n(e,""),this},this.propertyPatternEqualMode=function(){return this.description.propertyPatternTemplateMode=!1,this},this.propertyPatternTemplateMode=function(){return this.description.propertyPatternTemplateMode=!0,this},this.propertyPattern=function(e){return this.description.propertyPattern=n(e,""),this},this.indexStartsWith=function(e){return this.description.indexStartsWith=n(e,""),this},this.displayPropertyName=function(t){return this.description.getDisplayNameForPropertyName=e(t,this.description),o(t)||(this.description.getDisplayNameForPropertyName=(i=this.description.getDisplayNameForPropertyName,function(e){var t=i(e);return(t=null!=t?t:"").replace("_comma_separated_values","")}),this.description.getDisplayNameForPropertyName=function(e){return function(t){return function(e){return e.length>1?e.charAt(0).toUpperCase()+e.slice(1):e}(e(t))}}(this.description.getDisplayNameForPropertyName)),this;var i},this.fieldName=function(t){return this.description.getFieldNameForPropertyName=e(t,this.description),this},this.groupName=function(e){return this.description.groupName=n(e,""),this},this.groupPattern=function(e){return this.description.groupPattern=n(e,""),this},this.groupDestinationPattern=function(e){return this.description.groupDestinationPattern=n(e,""),this},this.groupDestinationName=function(e){return this.description.groupDestinationName=n(e,this.description.groupName),this},this.deduplicationPattern=function(e){return this.description.deduplicationPattern=n(e,""),this},this.build=function(){var e,t;return this.description.matchesPropertyName=(e=this.description,o(t=e.propertyPattern)?e.propertyPatternTemplateMode?function(e){return null!=(r=t,n=new RegExp("\\\\\\{\\\\\\{[-\\w]+\\\\\\}\\\\\\}","gi"),i(r,n)).exec(e);var r,n}:function(e){return e===t}:function(){return!1}),null==this.description.getDisplayNameForPropertyName&&this.displayPropertyName(""),null==this.description.getFieldNameForPropertyName&&this.fieldName(""),null==this.description.groupDestinationName&&this.groupDestinationName(""),this.description}}}(),a.DescribedEntryCreator=function(){"use strict";var e=new RegExp("\\[\\d+\\]","gi");return function(t,i){var r,n,o=(r=t.name,n=new RegExp("\\[(\\d+)\\]","gi"),function(e,t){var i,r="",n=[];do{(i=t.exec(e))&&(r.length>0&&(r+="."),r+=i[1],n.push(parseInt(i[1])))}while(i);return{pointDelimited:r,numberArray:n}}(r,n)),a=t.name.replace(e,""),s=new u.Resolver(this);this.category=i.category,this.type=i.type,this.abbreviation=i.abbreviation,this.image=i.image,this.index=o.numberArray,this.displayName=i.getDisplayNameForPropertyName(a),this.fieldName=i.getFieldNameForPropertyName(a),this.value=t.value,this.groupNames=[],this._isMatchingIndex=0==o.pointDelimited.indexOf(i.indexStartsWith),this._description=i,this._identifier={index:o.pointDelimited,propertyNameWithArrayIndices:t.name,propertyNameWithoutArrayIndices:a,groupId:"",groupDestinationId:"",deduplicationId:""},this._identifier.groupId=s.replaceResolvableFields(i.groupPattern,s.resolvableFieldsOfAll(this,this._description,this._identifier)),this._identifier.groupDestinationId=s.replaceResolvableFields(i.groupDestinationPattern,s.resolvableFieldsOfAll(this,this._description,this._identifier)),this._identifier.deduplicationId=s.replaceResolvableFields(i.deduplicationPattern,s.resolvableFieldsOfAll(this,this._description,this._identifier)),this.addGroupEntry=function(e,t){this.addGroupEntries(e,[t])},this.addGroupEntries=function(e,t){var i,r;for(this[e]||(this.groupNames.push(e),this[e]=[]),i=0;i<t.length;i+=1)r=t[i],this[e].push(r)}}}(),a.Transform=function(){"use strict";function e(e,t,i){var r,n,o,a=function(e,t){for(var i=new Object,r=0;r<e.length;r++){var n=e[r];i[t(n)]=n}return i}(t,i),s=[];for(r=0;r<e.length;r+=1)null!=(o=i(n=e[r]))&&""!==o&&null!=a[o]||s.push(n);for(r=0;r<t.length;r+=1)n=t[r],s.push(n);return s}function t(t,i){if(null==t||0==t.length)return i;return e(t,i,(function(e){return e._identifier.deduplicationId}))}function i(e,t){var i=new RegExp("\\[\\d+\\]","gi"),r=[];return e.filter((function(e){var n=e.name.replace(i,"");if(t.matchesPropertyName(n)){var o=new a.DescribedEntryCreator(e,t);o._isMatchingIndex&&r.push(o)}})),r}function r(e,t){var i=(new c.DescribedDataFieldBuilder).category(e.category).type(e.type).abbreviation(e.abbreviation).image(e.image).index(e.index).displayName(e.displayName).fieldName(e.fieldName).value(e.value).build();if(t.recursionDepth>t.config.maxRecursionDepth)return i;var o=null,a="",s=new c.DescribedDataFieldGroup(i);return function(e,t){var i,r,n;for(i=0;i<e.groupNames.length;i+=1)for(n=e.groupNames[i],r=0;r<e[n].length;r+=1)t(n,e[n][r],e[n])}(e,(function(e,i,u){t.groupToSkip!==e?(a="",t.recursionDepth>=t.config.removeDuplicationAboveRecursionDepth&&(a=function(e,t,i){if(e===t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;for(var r=0;r<e.length;++r)if(!i(e[r],t[r]))return!1;return!0}(i[e],u,n)?e:""),o={recursionDepth:t.recursionDepth+1,config:t.config,groupToSkip:a},s.addGroupEntry(e,r(i,o))):t.config.debugMode&&console.log("Removed duplicate group "+e+" at recursion depth "+t.recursionDepth)})),i}function n(e,t){return o(e.category)===o(t.category)&&o(e.type)===o(t.type)&&e.fieldName===t.fieldName&&e.value===t.value}function o(e){return function(e,t){return void 0!==e&&e?e:t}(e,"")}return function(e){this.descriptions=e,this.config={debugMode:!1,maxRecursionDepth:8,removeDuplicationAboveRecursionDepth:1},this.enableDebugMode=function(){return this.config.debugMode=!0,this},this.setMaxRecursionDepth=function(e){if("number"!=typeof e||e<0)throw"Invalid max recursion depth value: "+e;return this.config.maxRecursionDepth=e,this},this.setRemoveDuplicationAboveRecursionDepth=function(e){if("number"!=typeof e||e<0)throw"Invalid remove duplications above recursion depth value: "+e;return this.config.removeDuplicationAboveRecursionDepth=e,this},this.processJson=function(e){return function(e,n,o){var a=s.flattenToArray(e);a=function(e){var t=new RegExp("\\[\\d+\\]$","gi"),i=[],r="",n="";return e.filter((function(e){if(!e.name.match(t))return""!==r&&(i.push({name:r+"_comma_separated_values",value:n}),r=""),void i.push(e);var o=e.name.replace(t,"");r===o?n+=", "+e.value:(""!==r&&(i.push({name:r+"_comma_separated_values",value:n}),r=""),r=o,n=e.value),i.push(e)})),i}(a),o.debugMode&&(console.log("flattened data with array values:"),console.log(a));var u,c=[];for(u=0;u<n.length;u+=1)c=t(c,i(a,n[u]));a=c,o.debugMode&&(console.log("describedData data:"),console.log(a));a=function(e){return function(e,t,i){for(var r=new Object,n=0;n<e.length;n++){var o=e[n],a=t(o);if(""!==a){var s=i(o);null!=s&&""!==s&&(r[a]||(r[a]=o),r[a].addGroupEntry(s,o))}}return r}(e,(function(e){return e._identifier.groupId}),(function(e){return e._description.groupName}))}(a),o.debugMode&&(console.log("grouped describedData data:"),console.log(a));a=function(e){for(var t=Object.keys(e),i=[],r=0;r<t.length;r++){var n=t[r],o=e[n];if(""!=o._description.groupDestinationPattern){var a=o._identifier.groupDestinationId;if(null!=e[a]){var s=o[o._description.groupName];e[a].addGroupEntries(o._description.groupDestinationName,s),i.push(n)}}}for(r=0;r<i.length;r+=1){delete e[i[r]]}return e}(a),o.debugMode&&(console.log("moved grouped describedData data:"),console.log(a));a=function(e,t){var i,n,o=[];for(i=0;i<e.length;i+=1)n=e[i],o.push(r(n,{recursionDepth:0,config:t,groupToSkip:""}));return o}(a=function(e){for(var t=[],i=Object.keys(e),r=0;r<i.length;r++){var n=e[i[r]];t.push(n)}return t}(a),o),o.debugMode&&(console.log("transformed result:"),console.log(a));return a}(e,this.descriptions,this.config)}}}(),a.Restructor={},a.Restructor.processJsonUsingDescriptions=function(e,t,i){var r=new a.Transform(t);return i&&r.enableDebugMode(),r.processJson(e)};
1
+ var e=globalThis,t={},i={},r=e.parcelRequirec1f2;null==r&&((r=function(e){if(e in t)return t[e].exports;if(e in i){var r=i[e];delete i[e];var n={id:e,exports:{}};return t[e]=n,r.call(n.exports,n,n.exports),n.exports}var o=Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,t){i[e]=t},e.parcelRequirec1f2=r);var n=r.register;n("cB1fX",function(e,t){var i,n=o(n);// Fallback for vanilla js without modules
2
+ function o(e){return e||{}}/**
3
+ * datarestructor namespace and module declaration.
4
+ * It contains all functions to convert an object (e.g. parsed JSON) into uniform enumerated list of described field entries.
5
+ *
6
+ * <b>Transformation steps:</b>
7
+ * - JSON
8
+ * - flatten
9
+ * - mark and identify
10
+ * - add array fields
11
+ * - deduplicate
12
+ * - group
13
+ * - flatten again
14
+ * @module datarestructor
15
+ */var a=n.exports={};// Export module for npm...
16
+ a.internalCreateIfNotExists=o;var s=s||r("7HmuL"),u=u||r("8ZIyB"),l=l||r("d63jw");// supports vanilla js & npm
17
+ /**
18
+ * Takes the full qualified original property name and extracts a simple name out of it.
19
+ *
20
+ * @callback module:datarestructor.propertyNameFunction
21
+ * @param {string} propertyName full qualified, point separated property name
22
+ * @return {String} extracted, simple name
23
+ *//**
24
+ * Describes a selected part of the incoming data structure and defines,
25
+ * how the data should be transformed.
26
+ *
27
+ * @typedef {Object} module:datarestructor.PropertyStructureDescription
28
+ * @property {string} type - ""(default). Some examples: "summary" for e.g. a list overview. "detail" e.g. when a summary is selected. "filter" e.g. for field/value pair results that can be selected as search parameters.
29
+ * @property {string} category - name of the category. Default = "". Could contain a short domain name like "product" or "vendor".
30
+ * @property {string} [abbreviation=""] - one optional character, a symbol character or a short abbreviation of the category
31
+ * @property {string} [image=""] - one optional path to an image resource
32
+ * @property {boolean} propertyPatternTemplateMode - "false"(default): property name needs to be equal to the pattern. "true" allows variables like "{{fieldName}}" inside the pattern.
33
+ * @property {string} propertyPattern - property name pattern (without array indices) to match
34
+ * @property {string} indexStartsWith - ""(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".
35
+ * @property {module:datarestructor.propertyNameFunction} getDisplayNameForPropertyName - display name for the property. ""(default) last property name element with upper case first letter.
36
+ * @property {module:datarestructor.propertyNameFunction} getFieldNameForPropertyName - field name for the property. "" (default) last property name element.
37
+ * @property {string} groupName - name of the property, that contains grouped entries. Default="group".
38
+ * @property {string} groupPattern - Pattern that describes how to group entries. "groupName" defines the name of this group. A pattern may contain variables in double curly brackets {{variable}}.
39
+ * @property {string} groupDestinationPattern - 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}}.
40
+ * @property {string} groupDestinationName - (default=groupName) Name of the group when it had been moved to the destination.
41
+ * @property {string} deduplicationPattern - Pattern to use to remove duplicate entries. A pattern may contain variables in double curly brackets {{variable}}.
42
+ */a.PropertyStructureDescriptionBuilder=function(){function e(e,r){var n;return o(e)?function(){return e}:r.propertyPatternTemplateMode?(n=r.propertyPattern,function(e){var r=i(n,"{{fieldName}}").exec(e);return r&&""!=r[1]?r[1]:t(e)}):function(e){return t(e)}}function t(e){var t=RegExp("(\\w+)$","gi"),i=e.match(t);return null!=i?i[0]:e}function i(e,t){var i=r(e);return"string"==typeof t&&(t=r(t)),RegExp(i="^"+(i=i.replace(t,"([-\\w]+)")),"i")}function r(e){var t=RegExp("([^-\\w])","gi");return e.replace(t,"\\$1")}function n(e,t){return o(e)?e:t}function o(e){return"string"==typeof e&&null!=e&&""!=e}return(/**
43
+ * Builder for a {@link PropertyStructureDescription}.
44
+ * @constructs PropertyStructureDescriptionBuilder
45
+ * @alias module:datarestructor.PropertyStructureDescriptionBuilder
46
+ */function(){/**
47
+ * @type {module:datarestructor.PropertyStructureDescription}
48
+ */this.description={type:"",category:"",abbreviation:"",image:"",propertyPatternTemplateMode:!1,propertyPattern:"",indexStartsWith:"",groupName:"group",groupPattern:"",groupDestinationPattern:"",groupDestinationName:null,deduplicationPattern:"",getDisplayNameForPropertyName:null,getFieldNameForPropertyName:null,matchesPropertyName:null},/**
49
+ * Sets the type.
50
+ *
51
+ * Contains the type of the entry, for example:
52
+ * - "summary" for e.g. a list overview.
53
+ * - "detail" e.g. when a summary is selected.
54
+ * - "filter" e.g. for field/value pair results that can be selected as search parameters.
55
+ *
56
+ * @function
57
+ * @param {String} [value=""]
58
+ * @returns {module:datarestructor.PropertyStructureDescription}
59
+ * @example type("summary")
60
+ */this.type=function(e){return this.description.type=n(e,""),this},/**
61
+ * Sets the category.
62
+ *
63
+ * Contains a short domain nam, for example:
64
+ * - "product" for products
65
+ * - "vendor" for vendors
66
+ *
67
+ * @function
68
+ * @param {String} [value=""]
69
+ * @returns {module:datarestructor.PropertyStructureDescription}
70
+ * @example category("Product")
71
+ */this.category=function(e){return this.description.category=n(e,""),this},/**
72
+ * Sets the optional abbreviation.
73
+ *
74
+ * Contains a symbol character or a very short abbreviation of the category.
75
+ * - "P" for products
76
+ * - "V" for vendors
77
+ *
78
+ * @function
79
+ * @param {String} [value=""]
80
+ * @returns {module:datarestructor.PropertyStructureDescription}
81
+ * @example abbreviation("P")
82
+ */this.abbreviation=function(e){return this.description.abbreviation=n(e,""),this},/**
83
+ * Sets the optional path to an image resource.
84
+ *
85
+ * @function
86
+ * @param {String} [value=""]
87
+ * @returns {module:datarestructor.PropertyStructureDescription}
88
+ * @example image("img/product.png")
89
+ */this.image=function(e){return this.description.image=n(e,""),this},/**
90
+ * Sets "equal mode" for the property pattern.
91
+ *
92
+ * "propertyPattern" need to match exactly if this mode is activated.
93
+ * It clears propertyPatternTemplateMode which means "equal" mode.
94
+ * @function
95
+ * @returns {module:datarestructor.PropertyStructureDescription}
96
+ */this.propertyPatternEqualMode=function(){return this.description.propertyPatternTemplateMode=!1,this},/**
97
+ * Sets "template mode" for the property pattern.
98
+ *
99
+ * "propertyPattern" can contain variables like {{fieldName}} and
100
+ * doesn't need to match the property name exactly. If the "propertyPattern"
101
+ * is shorter than the property name, it also matches when the property name
102
+ * starts with the "propertyPattern".
103
+ *
104
+ * @function
105
+ * @returns {module:datarestructor.PropertyStructureDescription}
106
+ */this.propertyPatternTemplateMode=function(){return this.description.propertyPatternTemplateMode=!0,this},/**
107
+ * Sets the property name pattern.
108
+ *
109
+ * Contains single property names with sub types separated by "." without array indices.
110
+ * May contain variables in double curly brackets.
111
+ *
112
+ * Example:
113
+ * - responses.hits.hits._source.{{fieldName}}
114
+ * @function
115
+ * @param {String} [value=""]
116
+ * @returns {module:datarestructor.PropertyStructureDescription}
117
+ * @example propertyPattern("responses.hits.hits._source.{{fieldName}}")
118
+ */this.propertyPattern=function(e){return this.description.propertyPattern=n(e,""),this},/**
119
+ * Sets the optional beginning of the id that needs to match.
120
+ * Matches all indices if set to "" (or not called).
121
+ *
122
+ * For example:
123
+ * - "1." will match id="1.3.4" but not "0.1.2".
124
+ * @function
125
+ * @param {String} [value=""]
126
+ * @returns {module:datarestructor.PropertyStructureDescription}
127
+ * @example indexStartsWith("1.")
128
+ */this.indexStartsWith=function(e){return this.description.indexStartsWith=n(e,""),this},/**
129
+ * Overrides the display name of the property.
130
+ *
131
+ * If it is not set or set to "" then it will be derived from the
132
+ * last part of original property name starting with an upper case character.
133
+ *
134
+ * For example:
135
+ * - "Product"
136
+ * @function
137
+ * @param {String} [value=""]
138
+ * @returns {module:datarestructor.PropertyStructureDescription}
139
+ * @example displayPropertyName("Product")
140
+ */this.displayPropertyName=function(t){var i,r;return this.description.getDisplayNameForPropertyName=e(t,this.description),o(t)||(this.description.getDisplayNameForPropertyName=(i=this.description.getDisplayNameForPropertyName,function(e){var t=i(e);return(t=null!=t?t:"").replace("_comma_separated_values","")}),this.description.getDisplayNameForPropertyName=(r=this.description.getDisplayNameForPropertyName,function(e){var t;return(t=r(e)).length>1?t.charAt(0).toUpperCase()+t.slice(1):t})),this},/**
141
+ * Overrides the (technical) field name of the property.
142
+ *
143
+ * If it is not set or set to "" then it will be derived from the
144
+ * last part of original property name.
145
+ *
146
+ * For example:
147
+ * - "product"
148
+ * @function
149
+ * @param {String} [value=""]
150
+ * @returns {module:datarestructor.PropertyStructureDescription}
151
+ * @example fieldName("product")
152
+ */this.fieldName=function(t){return this.description.getFieldNameForPropertyName=e(t,this.description),this},/**
153
+ * Sets the name of the property, that contains grouped entries.
154
+ *
155
+ * @function
156
+ * @param {String} [value=""]
157
+ * @returns {module:datarestructor.PropertyStructureDescription}
158
+ * @example groupName("details")
159
+ */this.groupName=function(e){return this.description.groupName=n(e,""),this},/**
160
+ * Sets the pattern that describes how to group entries.
161
+ *
162
+ * "groupName" defines the name of this group.
163
+ * A pattern may contain variables in double curly brackets {{variable}}.
164
+ * @function
165
+ * @param {String} [value=""]
166
+ * @returns {module:datarestructor.PropertyStructureDescription}
167
+ * @example groupPattern("{{type}}-{{category}}")
168
+ */this.groupPattern=function(e){return this.description.groupPattern=n(e,""),this},/**
169
+ * Sets the pattern that describes where the group should be moved to.
170
+ *
171
+ * Default=""=Group will not be moved.
172
+ * A pattern may contain variables in double curly brackets {{variable}}.
173
+ * @function
174
+ * @param {String} [value=""]
175
+ * @returns {module:datarestructor.PropertyStructureDescription}
176
+ * @example groupDestinationPattern("main-{{category}}")
177
+ */this.groupDestinationPattern=function(e){return this.description.groupDestinationPattern=n(e,""),this},/**
178
+ * Sets the name of the group when it had been moved to the destination.
179
+ *
180
+ * The default value is the groupName, which will be used when the value is not valid (null or empty)
181
+ * @function
182
+ * @param {String} [value=""]
183
+ * @returns {module:datarestructor.PropertyStructureDescription}
184
+ * @example groupDestinationPattern("options")
185
+ */this.groupDestinationName=function(e){return this.description.groupDestinationName=n(e,this.description.groupName),this},/**
186
+ * Sets the pattern to be used to remove duplicate entries.
187
+ *
188
+ * A pattern may contain variables in double curly brackets {{variable}}.
189
+ * A pattern may contain variables in double curly brackets {{variable}}.
190
+ * @function
191
+ * @param {String} [value=""]
192
+ * @returns {module:datarestructor.PropertyStructureDescription}
193
+ * @example deduplicationPattern("{{category}}--{{type}}--{{index[0]}}--{{index[1]}}--{{fieldName}}")
194
+ */this.deduplicationPattern=function(e){return this.description.deduplicationPattern=n(e,""),this},/**
195
+ * Finalizes the settings and builds the PropertyStructureDescription.
196
+ * @function
197
+ * @returns {module:datarestructor.PropertyStructureDescription}
198
+ */this.build=function(){var e,t;return this.description.matchesPropertyName=o(t=(e=this.description).propertyPattern)?e.propertyPatternTemplateMode?function(e){return null!=i(t,RegExp("\\\\\\{\\\\\\{[-\\w]+\\\\\\}\\\\\\}","gi")).exec(e)}:function(e){return e===t}:function(){return!1;// Without a propertyPattern, no property will match (deactivated mark/identify).
199
+ },null==this.description.getDisplayNameForPropertyName&&this.displayPropertyName(""),null==this.description.getFieldNameForPropertyName&&this.fieldName(""),null==this.description.groupDestinationName&&this.groupDestinationName(""),this.description}})}(),/**
200
+ * Adds a group item/entry to the {@link module:datarestructor.DescribedEntry}.
201
+ *
202
+ * @callback module:datarestructor.addGroupEntryFunction
203
+ * @param {String} groupName name of the group that should be added
204
+ * @param {module:datarestructor.DescribedEntry} describedEntry entry that should be added to the group
205
+ *//**
206
+ * Adds some group items/entries to the {@link module:datarestructor.DescribedEntry}.
207
+ *
208
+ * @callback module:datarestructor.addGroupEntriesFunction
209
+ * @param {String} groupName name of the group that should be added
210
+ * @param {module:datarestructor.DescribedEntry[]} describedEntry entries that should be added to the group
211
+ *//**
212
+ * @typedef {Object} module:datarestructor.DescribedEntry
213
+ * @property {string} category - category of the result from the PropertyStructureDescription using a short name or e.g. a symbol character
214
+ * @property {string} type - type of the result from PropertyStructureDescription
215
+ * @property {string} [abbreviation=""] - one optional character, a symbol character or a short abbreviation of the category
216
+ * @property {string} [image=""] - one optional path to an image resource
217
+ * @property {string} index - array of numbers containing the split index. Example: "responses[2].hits.hits[4]._source.name" leads to an array with the two elements: [2,4]
218
+ * @property {string} displayName - display name extracted from the point separated hierarchical property name, e.g. "Name"
219
+ * @property {string} fieldName - field name extracted from the point separated hierarchical property name, e.g. "name"
220
+ * @property {string} value - content of the field
221
+ * @property {string[]} groupNames - array of names of all dynamically added properties representing groups
222
+ * @property {module:datarestructor.addGroupEntryFunction} addGroupEntry - function, that adds an entry to the given group. If the group does not exist, it will be created.
223
+ * @property {module:datarestructor.addGroupEntriesFunction} addGroupEntries - function, that adds entries to the given group. If the group does not exist, it will be created.
224
+ * @property {boolean} _isMatchingIndex - true, when _identifier.index matches the described "indexStartsWith"
225
+ * @property {Object} _identifier - internal structure for identifier. Avoid using it outside since it may change.
226
+ * @property {string} _identifier.index - array indices in hierarchical order separated by points, e.g. "0.0"
227
+ * @property {string} _identifier.value - the (single) value of the "flattened" property, e.g. "Smith"
228
+ * @property {string} _identifier.propertyNameWithArrayIndices - the "original" flattened property name in hierarchical order separated by points, e.g. "responses[0].hits.hits[0]._source.name"
229
+ * @property {string} _identifier.propertyNameWithoutArrayIndices - same as propertyNamesWithArrayIndices but without array indices, e.g. "responses.hits.hits._source.name"
230
+ * @property {string} _identifier.groupId - Contains the resolved groupPattern from the PropertyStructureDescription. Entries with the same id will be grouped into the "groupName" of the PropertyStructureDescription.
231
+ * @property {string} _identifier.groupDestinationId - Contains the resolved groupDestinationPattern from the PropertyStructureDescription. Entries with this id will be moved to the given destination group.
232
+ * @property {string} _identifier.deduplicationId - Contains the resolved deduplicationPattern from the PropertyStructureDescription. Entries with the same id will be considered to be a duplicate and hence removed.
233
+ * @property {Object} _description - PropertyStructureDescription for internal use. Avoid using it outside since it may change.
234
+ *//**
235
+ * Returns a field value of the given {@link module:datarestructor.DescribedEntry}.
236
+ *
237
+ * @callback module:datarestructor.stringFieldOfDescribedEntryFunction
238
+ * @param {module:datarestructor.DescribedEntry} entry described entry that contains the field that should be returned
239
+ * @returns {String} field value
240
+ */a.DescribedEntryCreator=(i=RegExp("\\[\\d+\\]","gi"),/**
241
+ * Creates a {@link module:datarestructor.DescribedEntry}.
242
+ * @constructs DescribedEntryCreator
243
+ * @alias module:datarestructor.DescribedEntryCreator
244
+ */function(e,t){var r=/**
245
+ * Returns "1.12.123" and [1,12,123] for "results[1].hits.hits[12].aggregates[123]".
246
+ *
247
+ * @param {string} fullPropertyName
248
+ * @param {RegExp} regexWithOneNumberGroup
249
+ * @return {module:datarestructor.ExtractedIndices} extracted indices in different representations
250
+ * @protected
251
+ * @memberof module:datarestructor.DescribedEntryCreator
252
+ */function(e,t){var i,r="",n=[];do(i=t.exec(e))&&(r.length>0&&(r+="."),r+=i[1],n.push(parseInt(i[1])));while(i)return{pointDelimited:r,numberArray:n}}(e.name,RegExp("\\[(\\d+)\\]","gi")),n=e.name.replace(i,""),o=new u.Resolver(this);this.category=t.category,this.type=t.type,this.abbreviation=t.abbreviation,this.image=t.image,/**
253
+ * Array of numbers containing the split index.
254
+ * Example: "responses[2].hits.hits[4]._source.name" leads to an array with two elements: [2,4]
255
+ * This is the public version of the internal variable _identifier.index, which contains in contrast all index elements in one point separated string (e.g. "2.4").
256
+ * @type {number[]}
257
+ */this.index=r.numberArray,this.displayName=t.getDisplayNameForPropertyName(n),this.fieldName=t.getFieldNameForPropertyName(n),this.value=e.value,this.groupNames=[],this._isMatchingIndex=0==r.pointDelimited.indexOf(t.indexStartsWith),this._description=t,this._identifier={index:r.pointDelimited,propertyNameWithArrayIndices:e.name,propertyNameWithoutArrayIndices:n,groupId:"",groupDestinationId:"",deduplicationId:""},this._identifier.groupId=o.replaceResolvableFields(t.groupPattern,o.resolvableFieldsOfAll(this,this._description,this._identifier)),this._identifier.groupDestinationId=o.replaceResolvableFields(t.groupDestinationPattern,o.resolvableFieldsOfAll(this,this._description,this._identifier)),this._identifier.deduplicationId=o.replaceResolvableFields(t.deduplicationPattern,o.resolvableFieldsOfAll(this,this._description,this._identifier)),/**
258
+ * Adds an entry to the given group. If the group does not exist, it will be created.
259
+ * @param {String} groupName name of the group that should be added
260
+ * @param {module:datarestructor.DescribedEntry} describedEntry entry that should be added to the group
261
+ */this.addGroupEntry=function(e,t){this.addGroupEntries(e,[t])},/**
262
+ * Adds entries to the given group. If the group does not exist, it will be created.
263
+ * @param {String} groupName
264
+ * @param {module:datarestructor.DescribedEntry[]} describedEntries
265
+ */this.addGroupEntries=function(e,t){var i,r;for(this[e]||(this.groupNames.push(e),this[e]=[]),i=0;i<t.length;i+=1)r=t[i],this[e].push(r)}}),/**
266
+ * @typedef {Object} module:datarestructor.TransformConfig
267
+ * @property {boolean} debugMode enables/disables detailed logging
268
+ * @property {number} [maxRecursionDepth=8] Maximum recursion depth
269
+ * @property {number} [removeDuplicationAboveRecursionDepth=1] Duplications will be removed above the given recursion depth value and remain unchanged below it.
270
+ */a.Transform=function(){function e(e,i){var r,n,o,a;return t(e.category,"")===t(i.category,"")&&t(e.type,"")===t(i.type,"")&&e.fieldName===i.fieldName&&e.value===i.value}function t(e,t){return void 0!==e&&e?e:t}return(/**
271
+ * Main class for the data transformation.
272
+ * @param {module:datarestructor.PropertyStructureDescription[]} descriptions
273
+ * @constructs Transform
274
+ * @alias module:datarestructor.Transform
275
+ */function(t){/**
276
+ * Descriptions of the input data that define the behaviour of the transformation.
277
+ * @type {module:datarestructor.DescribedEntry[]}
278
+ */this.descriptions=t,/**
279
+ * Configuration for the transformation.
280
+ * @protected
281
+ * @type {module:datarestructor.TransformConfig}
282
+ */this.config={/**
283
+ * Debug mode switch, that enables/disables detailed logging.
284
+ * @protected
285
+ * @type {boolean}
286
+ */debugMode:!1,/**
287
+ * Maximum recursion depth. Defaults to 8.
288
+ * @protected
289
+ * @type {number}
290
+ */maxRecursionDepth:8,/**
291
+ * Duplications will be removed above the given recursion depth and remain below it.
292
+ * Defaults to 1.
293
+ *
294
+ * Since fields can contain groups of fields that can contain groups of fields..., cyclic
295
+ * data structures are possible by nature and will lead to duplications. Some of them
296
+ * might be intended e.g. to take one (sub-)field with all (duplicated) groups.
297
+ * To restrict duplications and improve performance it is beneficial to define a
298
+ * recursion depth, above which further duplication won't be used and should be removed/avoided.
299
+ *
300
+ * @protected
301
+ * @type {number}
302
+ */removeDuplicationAboveRecursionDepth:1},/**
303
+ * Enables debug mode. Logs additional information.
304
+ * @returns {module:datarestructor.Transform}
305
+ */this.enableDebugMode=function(){return this.config.debugMode=!0,this},/**
306
+ * Sets the maximum recursion depth. Defaults to 8 if not set.
307
+ * @param {number} value non negative number.
308
+ * @returns {module:datarestructor.Transform}
309
+ */this.setMaxRecursionDepth=function(e){if("number"!=typeof e||e<0)throw"Invalid max recursion depth value: "+e;return this.config.maxRecursionDepth=e,this},/**
310
+ * Sets the recursion depth above which duplication will be removed. Duplications below it remain unchanged.
311
+ * Defaults to 1.
312
+ *
313
+ * Since fields can contain groups of fields that can contain groups of fields..., cyclic
314
+ * data structures are possible by nature and will lead to duplications. Some of them
315
+ * might be intended e.g. to take one (sub-)field with all (duplicated) groups.
316
+ * To restrict duplications and improve performance it is beneficial to define a
317
+ * recursion depth, above which further duplication won't be used and should be removed/avoided.
318
+ *
319
+ * @param {number} value non negative number.
320
+ * @returns {module:datarestructor.Transform}
321
+ */this.setRemoveDuplicationAboveRecursionDepth=function(e){if("number"!=typeof e||e<0)throw"Invalid remove duplications above recursion depth value: "+e;return this.config.removeDuplicationAboveRecursionDepth=e,this},/**
322
+ * "Assembly line", that takes the (pared JSON) data and processes it using all given descriptions in their given order.
323
+ * @param {object} data - parsed JSON data or any other data object
324
+ * @returns {module:datarestructor.DescribedEntry[]}
325
+ * @example
326
+ * var allDescriptions = [];
327
+ * allDescriptions.push(summariesDescription());
328
+ * allDescriptions.push(detailsDescription());
329
+ * var result = new datarestructor.Transform(allDescriptions).processJson(jsonData);
330
+ */this.processJson=function(t){return(/**
331
+ * "Assembly line", that takes the jsonData and processes it using all given descriptions in their given order.
332
+ * @param {object} jsonData parsed JSON data or any other data object
333
+ * @param {module:datarestructor.PropertyStructureDescription[]} descriptions - already grouped entries
334
+ * @param {module:datarestructor.TransformConfig} config configuration for the data transformation
335
+ * @returns {module:datarestructor.DescribedEntry[]}
336
+ * @protected
337
+ * @memberof module:datarestructor.Transform
338
+ */function(t,i,r){// "Flatten" the hierarchical input json to an array of property names (point separated "folders") and values.
339
+ var n,o,u,p,d,c,h,f,g=s.flattenToArray(t);n=g,o=RegExp("\\[\\d+\\]$","gi"),u=[],p="",d="",n.filter(function(e){if(!e.name.match(o)){""!==p&&(u.push({name:p+"_comma_separated_values",value:d}),p=""),u.push(e);return}var t=e.name.replace(o,"");p===t?d+=", "+e.value:(""!==p&&(u.push({name:p+"_comma_separated_values",value:d}),p=""),p=t,d=e.value),u.push(e)}),// Fill in properties ending with the name "_comma_separated_values" for array values to make it easier to display them.
340
+ g=u,r.debugMode&&(console.log("flattened data with array values:"),console.log(g));// Mark, identify and harmonize the flattened data by applying one description after another in their given order.
341
+ var m=[];for(f=0;f<i.length;f+=1)// Remove duplicate entries where a deduplicationPattern is described
342
+ c=m,h=/**
343
+ * Extracts entries out of "flattened" JSON data and provides an array of objects.
344
+ * @param {Object[]} flattenedData - flattened json from search query result
345
+ * @param {string} flattenedData[].name - name of the property in hierarchical order separated by points
346
+ * @param {string} flattenedData[].value - value of the property as string
347
+ * @param {module:datarestructor.PropertyStructureDescription} - description of structure of the entries that should be extracted
348
+ * @return {module:datarestructor.DescribedEntry[]}
349
+ * @protected
350
+ * @memberof module:datarestructor.Transform
351
+ */function(e,t){var i=RegExp("\\[\\d+\\]","gi"),r=[];return e.filter(function(e){var n=e.name.replace(i,"");if(t.matchesPropertyName(n)){var o=new a.DescribedEntryCreator(e,t);o._isMatchingIndex&&r.push(o)}}),r}(g,i[f]),m=null==c||0==c.length?h:/**
352
+ * Takes two arrays of objects, e.g. [{id: B, value: 2},{id: C, value: 3}]
353
+ * and [{id: A, value: 1},{id: B, value: 4}] and merges them into one:
354
+ * [{id: C, value: 3},{id: A, value: 1},{id: B, value: 4}]
355
+ *
356
+ * Entries with the same id ("duplicates") will be overwritten.
357
+ * Only the last element with the same id remains. The order is
358
+ * determined by the order of the array elements, whereas the first
359
+ * array comes before the second one. This means, that entries with the
360
+ * same id in the second array overwrite entries in the first array,
361
+ * and entries that occur later in the array overwrite earlier ones,
362
+ * if they have the same id.
363
+ *
364
+ * The id is extracted from every element using the given function.
365
+ *
366
+ * @param {module:datarestructor.DescribedEntry[]} entries
367
+ * @param {module:datarestructor.DescribedEntry[]} entriesToMerge
368
+ * @param {module:datarestructor.stringFieldOfDescribedEntryFunction} idOfElementFunction returns the id of an DescribedEntry
369
+ * @protected
370
+ * @memberof module:datarestructor.Transform
371
+ */function(e,t,i){var r,n,o,a=/**
372
+ * Converts the given elements to an object, that provides these
373
+ * entries by their id. For example, [{id: A, value: 1}] becomes
374
+ * result['A'] = 1.
375
+ * @param {module:datarestructor.DescribedEntry[]} elements of DescribedEntry elements
376
+ * @param {module:datarestructor.stringFieldOfDescribedEntryFunction} idOfElementFunction returns the id of an DescribedEntry
377
+ * @return {module:datarestructor.DescribedEntry[] entries indexed by id
378
+ * @protected
379
+ * @memberof module:datarestructor.Transform
380
+ */function(e,t){for(var i={},r=0;r<e.length;r++){var n=e[r];i[t(n)]=n}return i}(t,i),s=[];for(r=0;r<e.length;r+=1)(null==(o=i(n=e[r]))||""===o||null==a[o])&&s.push(n);for(r=0;r<t.length;r+=1)s.push(n=t[r]);return s}(c,h,function(e){return e._identifier.deduplicationId});return g=m,r.debugMode&&(console.log("describedData data:"),console.log(g)),// Group entries where a groupPattern is described
381
+ g=/**
382
+ * Converts the given elements into an object, that provides these
383
+ * entries by their id. For example, [{id: A, value: 1}] becomes
384
+ * result['A'] = 1. Furthermore, this function creates a group property (with the name )
385
+ * and collects all related elements (specified by their group pattern) in it.
386
+ *
387
+ * @param {module:datarestructor.DescribedEntry[]} elements of DescribedEntry elements
388
+ * @param {module:datarestructor.stringFieldOfDescribedEntryFunction} groupNameOfElementFunction function, that returns the name of the group property that will be created inside the "main" element.
389
+ * @param {module:datarestructor.stringFieldOfDescribedEntryFunction} groupIdOfElementFunction returns the group id of an DescribedEntry
390
+ * @return {module:datarestructor.DescribedEntry[] entries indexed by id
391
+ * @protected
392
+ * @memberof module:datarestructor.Transform
393
+ */function(e,t,i){for(var r={},n=0;n<e.length;n++){var o=e[n],a=t(o);if(""!==a){var s=i(o);null!=s&&""!==s&&(r[a]||(r[a]=o),r[a].addGroupEntry(s,o))}}return r}(g,function(e){return e._identifier.groupId},function(e){return e._description.groupName}),r.debugMode&&(console.log("grouped describedData data:"),console.log(g)),// Move group entries where a groupDestinationPattern is described
394
+ g=/**
395
+ * Takes already grouped {@link module:datarestructor.DescribedEntry} objects and
396
+ * uses their "_identifier.groupDestinationId" (if exists)
397
+ * to move groups to the given destination.
398
+ *
399
+ * This is useful, if separately described groups like "summary" and "detail" should be put together,
400
+ * so that every summery contains a group with the regarding details.
401
+ *
402
+ * @param {module:datarestructor.DescribedEntry[]} groupedObject - already grouped entries
403
+ * @return {module:datarestructor.DescribedEntry[]}
404
+ * @protected
405
+ * @memberof module:datarestructor.Transform
406
+ */function(e){for(var t=Object.keys(e),i=[],r=0;r<t.length;r++){var n=t[r],o=e[n];if(""!=o._description.groupDestinationPattern){var a=o._identifier.groupDestinationId;if(null!=e[a]){var s=o[o._description.groupName];e[a].addGroupEntries(o._description.groupDestinationName,s),i.push(n)}}}// delete all moved entries that had been collected by their key
407
+ for(r=0;r<i.length;r+=1){var u=i[r];delete e[u]}return e}(g),r.debugMode&&(console.log("moved grouped describedData data:"),console.log(g)),// Converts the internal described entries into described fields
408
+ g=/**
409
+ * Converts described entries (internal data structure) to described fields (external data structure).
410
+ * Since the structure of a described field is hierarchical, every field needs to be converted
411
+ * in a recursive manner. The maximum recursion depth is taken as the second parameter.
412
+ * @param {module:datarestructor.DescribedEntry[]} describedEntries
413
+ * @param {module:datarestructor.TransformConfig} config configuration for the data transformation
414
+ * @returns {module:described_field.DescribedDataField[]}
415
+ * @protected
416
+ * @memberof module:datarestructor.Transform
417
+ */function(t,i){var r,n=[];for(r=0;r<t.length;r+=1)n.push(/**
418
+ * Describes the context type for the recursive DescribedDataField conversion,
419
+ * that contains everything that needs to be accessible throughout recursion regardless of the
420
+ * recursion depth.
421
+ *
422
+ * @typedef {Object} module:datarestructor.DescribedFieldRecursionContext
423
+ * @param {number} recursionDepth current recursion depth
424
+ * @param {String} groupToSkip name of a group to skip or "" when no group should be skipped.
425
+ * @param {module:datarestructor.TransformConfig} config configuration for the data transformation
426
+ *//**
427
+ * Converts a internal described entry to a newly created public described field.
428
+ * Since the structure of a described field is hierarchical, this function is called recursively.
429
+ * Because the internal described entries may very likely contain cyclic references, the depth of recursion
430
+ * needs to be limited. Therefore, the current recursion depth is taken as second parameter
431
+ * and the maximum recursion depth is taken as third parameter.
432
+ * @param {module:datarestructor.DescribedEntry} entry the internal entry that will be converted
433
+ * @param {module:datarestructor.DescribedFieldRecursionContext} recursionContext context contains everything that needs to be accessible throughout the recursion.
434
+ * @returns {module:described_field.DescribedDataField}
435
+ * @protected
436
+ * @memberof module:datarestructor.Transform
437
+ */function t(i,r){var n=new l.DescribedDataFieldBuilder().category(i.category).type(i.type).abbreviation(i.abbreviation).image(i.image).index(i.index).displayName(i.displayName).fieldName(i.fieldName).value(i.value).build();if(r.recursionDepth>r.config.maxRecursionDepth)return n;var o=null,a="",s=new l.DescribedDataFieldGroup(n);return(/**
438
+ * Takes the full qualified original property name and extracts a simple name out of it.
439
+ *
440
+ * @callback module:datarestructor.onEntryFoundFunction
441
+ * @param {string} groupName name of the group where the entry had been found.
442
+ * @param {module:datarestructor.DescribedEntry} foundEntry the found entry itself.
443
+ * @param {module:datarestructor.DescribedEntry[]} allEntries the array of all entries where the found entry is an element of.
444
+ *//**
445
+ * Traverses through all groups and their entries and calls the given function on every found entry
446
+ * with the group name and the entry itself as parameters.
447
+ * @param {module:datarestructor.DescribedEntry} rootEntry
448
+ * @param {module:datarestructor.onEntryFoundFunction} onFoundEntry
449
+ * @protected
450
+ * @memberof module:datarestructor.Transform
451
+ */function(e,t){var i,r,n,o;for(i=0;i<e.groupNames.length;i+=1)for(r=0,n=e.groupNames[i];r<e[n].length;r+=1)o=e[n][r],t(n,o,e[n])}(i,function(i,n,u){if(r.groupToSkip===i){r.config.debugMode&&console.log("Removed duplicate group "+i+" at recursion depth "+r.recursionDepth);return}a="",r.recursionDepth>=r.config.removeDuplicationAboveRecursionDepth&&(a=!// Reference: https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript/16430730
452
+ // Added "elementEqualFunction" to implement equal object detection.
453
+ // Arrays are assumed to be sorted. Differently ordered entries are treated as not equal.
454
+ function(e,t,i){if(e===t)return!0;if(null==e||null==t||e.length!==t.length)return!1;for(var r=0;r<e.length;++r)if(!i(e[r],t[r]))return!1;return!0}(n[i],u,e)?"":i),o={recursionDepth:r.recursionDepth+1,config:r.config,groupToSkip:a},s.addGroupEntry(i,t(n,o))}),n)}(t[r],{recursionDepth:0,config:i,groupToSkip:""}));return n}(// Turns the grouped object back into an array of DescribedEntry-Objects
455
+ g=function(e){for(var t=[],i=Object.keys(e),r=0;r<i.length;r++){var n=e[i[r]];t.push(n)}return t}(g),r),r.debugMode&&(console.log("transformed result:"),console.log(g)),g}(t,this.descriptions,this.config))}})}(),/**
456
+ * Main fassade for the data restructor as static function(s).
457
+ *
458
+ * @example
459
+ * var allDescriptions = [];
460
+ * allDescriptions.push(summariesDescription());
461
+ * allDescriptions.push(detailsDescription());
462
+ * var result = datarestructor.Restructor.processJsonUsingDescriptions(jsonData, allDescriptions);
463
+ * @namespace module:datarestructor.Restructor
464
+ */a.Restructor={},/**
465
+ * Static fassade function for the "Assembly line", that takes the jsonData and processes it using all given descriptions in their given order.
466
+ * @param {object} jsonData - parsed JSON data or any other data object
467
+ * @param {module:datarestructor.PropertyStructureDescription[]} descriptions - already grouped entries
468
+ * @param {boolean} debugMode - false=default=off, true=write additional logs for detailed debugging
469
+ * @returns {module:datarestructor.DescribedEntry[]}
470
+ * @memberof module:datarestructor.Restructor
471
+ * @deprecated since v3.1.0, please use "new datarestructor.Transform(descriptions).processJson(jsonData)".
472
+ */a.Restructor.processJsonUsingDescriptions=function(e,t,i){var r=new a.Transform(t);return i&&r.enableDebugMode(),r.processJson(e)}}),n("7HmuL",function(e,t){/**
473
+ * @typedef {Object} NameValuePair
474
+ * @property {string} name - point separated names of the flattened main and sub properties, e.g. "responses[2].hits.hits[4]._source.name".
475
+ * @property {string} value - value of the property
476
+ *//**
477
+ * @param {object} data hierarchical object that may consist fo fields, subfields and arrays.
478
+ * @param {number} maxRecursionDepth
479
+ * @returns {NameValuePair[]} array of property name and value pairs
480
+ */(($59adffa3db62607f$var$module||{}).exports={}).flattenToArray=function(e,t){var i=[];return("number"!=typeof t||t<1)&&(t=20),function e(r,n,o){if(!(o>t)&&"function"!=typeof r){if(Object(r)!==r)i.push({name:n,value:r});else if(Array.isArray(r)){var a,s=r.length;for(a=0;a<s;a+=1)e(r[a],n+"["+a+"]",o+1);0===s&&(i[n]=[],i.push({name:n,value:""}))}else{var u,l=!0;for(u in r)l=!1,e(r[u],n?n+"."+u:u,o+1);l&&n&&i.push({name:n,value:""})}}}(e,"",0),i}}),n("8ZIyB",function(e,t){var i,n=o(n);// Fallback for vanilla js without modules
481
+ function o(e){return e||{}}/**
482
+ * Provides a simple template resolver, that replaces variables in double curly brackets with the values of a given object.
483
+ * @module template_resolver
484
+ */var a=n.exports={};// Export module for npm...
485
+ a.internalCreateIfNotExists=o;var s=s||r("7HmuL");// supports vanilla js & npm
486
+ a.Resolver=(i=RegExp("\\[\\d+\\]","gi"),/**
487
+ * Resolver. Is used inside this repository. It could also be used outside.
488
+ * @param {*} sourceDataObject The properties of this object will be used to replace the placeholders in the template.
489
+ * @constructs Resolver
490
+ * @alias module:template_resolver.Resolver
491
+ */function(e){/**
492
+ * The properties of this source data object will be used to replace the placeholders in the template.
493
+ */this.sourceDataObject=e,/**
494
+ * Resolves the given template.
495
+ *
496
+ * The template may contain variables in double curly brackets.
497
+ * Supported variables are all properties of this object, e.g. "{{fieldName}}", "{{displayName}}", "{{value}}".
498
+ * Since this object may also contains (described) groups of sub objects, they can also be used, e.g. "{{summaries[0].value}}"
499
+ * Parts of the index can be inserted by using e.g. "{{index[1]}}".
500
+ *
501
+ * @param {string} template
502
+ * @returns {string} resolved template
503
+ */this.resolveTemplate=function(e){return this.replaceResolvableFields(e,/**
504
+ * Adds the value of the "fieldName" property (including its group prefix) and its associated "value" property content.
505
+ * For example: detail[2].fieldName="name", detail[2].value="Smith" lead to the additional property detail.name="Smith".
506
+ * @param {object} object with resolvable field names and their values.
507
+ * @returns {object} object with resolvable field names and their values.
508
+ * @protected
509
+ * @memberof module:template_resolver.Resolver
510
+ */function(e){var t,r,n,o,a=Object.keys(e);for(t=0;t<a.length;t+=1)o=e[r=a[t]],"fieldName"===(n=/**
511
+ * Infos about the full property name including the name of the group (followed by the separator) and the name of the property itself.
512
+ * @param {String} fullPropertyName
513
+ * @returns {Object} Contains "group" (empty or group name including trailing separator "."), "groupWithoutArrayIndices" and "name" (property name).
514
+ * @protected
515
+ * @memberof module:template_resolver.Resolver
516
+ */function(e){var t=e.lastIndexOf("."),r=e;t>0&&(r=e.substr(t+1));var n="";t>0&&(n=e.substr(0,t+1));//includes the trailing ".".
517
+ var o=n.replace(i,"");return{group:n,groupWithoutArrayIndices:o,name:r}}(r)).name&&"fieldName"!==o&&(e[n.groupWithoutArrayIndices+o]=e[n.group+"value"]);return e}(this.resolvableFieldsOfAll(this.sourceDataObject)))},/**
518
+ * Returns a map like object, that contains all resolvable fields and their values as properties.
519
+ * This function takes a variable count of input parameters,
520
+ * each containing an object that contains resolvable fields to extract from.
521
+ *
522
+ * The recursion depth is limited to 3, so that an object,
523
+ * that contains an object can contain another object (but not further).
524
+ *
525
+ * Properties beginning with an underscore in their name will be filtered out, since they are considered as internal fields.
526
+ *
527
+ * @param {...object} varArgs variable count of parameters. Each parameter contains an object that fields should be resolvable for variables.
528
+ * @returns {object} object with resolvable field names and their values.
529
+ * @public
530
+ */this.resolvableFieldsOfAll=function(){var e,t={},i=function(e){return 0!==e.indexOf("_")&&0>e.indexOf("._")};for(e=0;e<arguments.length;e+=1)/**
531
+ * Collects all flattened name-value-pairs into one object using the property names as keys and their values as values (map-like).
532
+ * Example: `{name: "accountNumber", value: "12345"}` becomes `mapObject["accountNumber"]="12345"`.
533
+ *
534
+ * @param {NameValuePair[]} elements flattened array of name-value-pairs
535
+ * @param {object} mapObject container to collect the results. Needs to be created before e.g. using `{}`.
536
+ * @param {function} filterMatchesFunction takes the property name as string argument and returns true (include) or false (exclude).
537
+ * @protected
538
+ * @memberof module:template_resolver.Resolver
539
+ */(function(e,t,i){var r,n;for(r=0;r<e.length;r+=1)n=e[r],"function"==typeof i&&i(n.name)&&(t[n.name]=n.value)})(s.flattenToArray(arguments[e],3),t,i);return t},/**
540
+ * Replaces all variables in double curly brackets, e.g. {{property}},
541
+ * with the value of that property from the resolvableProperties.
542
+ *
543
+ * Supported property types: string, number, boolean
544
+ * @param {string} stringContainingVariables
545
+ * @param {object[]} resolvableFields (name=value)
546
+ */this.replaceResolvableFields=function(e,t){var i=e,r=Object.keys(t),n=0,o="",a="";for(n=0;n<r.length;n+=1)a=t[o=r[n]],i=i.replace("{{"+o+"}}",a);return i}})}),n("d63jw",function(e,t){var i=r(i);// Fallback for vanilla js without modules
547
+ function r(e){return e||{}}/**
548
+ * Describes a data field of the restructured data.
549
+ * @module described_field
550
+ */var n=i.exports={};// Export module for npm...
551
+ n.internalCreateIfNotExists=r,/**
552
+ * Describes a field of the restructured data.
553
+ * Dynamically added properties represent custom named groups containing DescribedDataField-Arrays.
554
+ *
555
+ * @typedef {Object} module:described_field.DescribedDataField
556
+ * @property {string} [category=""] - name of the category. Could contain a short domain name like "product" or "vendor".
557
+ * @property {string} [type=""] - type of the data element. Examples: "summary" for e.g. a list overview. "detail" e.g. when a summary is selected. "filter" e.g. for field/value pair results that can be selected as data filters.
558
+ * @property {string} [abbreviation=""] - one optional character, a symbol character or a short abbreviation of the category
559
+ * @property {string} [image=""] - one optional path to an image resource
560
+ * @property {string} index - array of numbers containing the splitted index. Example: "responses[2].hits.hits[4]._source.name" will have an index of [2,4]
561
+ * @property {string[]} groupNames - array of names of all dynamically added properties representing groups
562
+ * @property {string} displayName - display name of the field
563
+ * @property {string} fieldName - field name
564
+ * @property {{*}} value - content of the field
565
+ * @property {module:described_field.DescribedDataField[]} [couldBeAnyCustomGroupName] any number of groups attached to the field each containing multiple fields
566
+ */n.DescribedDataFieldBuilder=function(){function e(e,t){return"string"==typeof e&&null!==e&&""!==e?e:t}return(/**
567
+ * Builds a {@link module:described_field.DescribedDataField}.
568
+ * DescribedDataField is the main element of the restructured data and therefore considered "public".
569
+ * @constructs DescribedDataFieldBuilder
570
+ * @alias module:described_field.DescribedDataFieldBuilder
571
+ */function(){/**
572
+ * @type {module:described_field.DescribedDataField}
573
+ */this.describedField={category:"",type:"",abbreviation:"",image:"",index:[],groupNames:[],displayName:"",fieldName:"",value:""},/**
574
+ * Takes over all values of the template {@link module:described_field.DescribedDataField}.
575
+ * @function
576
+ * @param {module:described_field.DescribedDataField} template
577
+ * @returns {DescribedDataFieldBuilder}
578
+ * @example fromDescribedDataField(sourceField)
579
+ */this.fromDescribedDataField=function(e){return this.category(e.category),this.type(e.type),this.abbreviation(e.abbreviation),this.image(e.image),this.index(e.index),this.groupNames(e.groupNames),this.displayName(e.displayName),this.fieldName(e.fieldName),this.value(e.value),this},/**
580
+ * Sets the category.
581
+ *
582
+ * Contains a short domain nam, for example:
583
+ * - "product" for products
584
+ * - "vendor" for vendors
585
+ *
586
+ * @function
587
+ * @param {String} [value=""]
588
+ * @returns {DescribedDataFieldBuilder}
589
+ * @example category("Product")
590
+ */this.category=function(t){return this.describedField.category=e(t,""),this},/**
591
+ * Sets the type.
592
+ *
593
+ * Contains the type of the entry, for example:
594
+ * - "summary" for e.g. a list overview.
595
+ * - "detail" e.g. when a summary is selected.
596
+ * - "filter" e.g. for field/value pair results that can be selected as search parameters.
597
+ *
598
+ * @function
599
+ * @param {String} [value=""]
600
+ * @returns {DescribedDataFieldBuilder}
601
+ * @example type("summary")
602
+ */this.type=function(t){return this.describedField.type=e(t,""),this},/**
603
+ * Sets the optional abbreviation.
604
+ *
605
+ * Contains a symbol character or a very short abbreviation of the category.
606
+ * - "P" for products
607
+ * - "V" for vendors
608
+ *
609
+ * @function
610
+ * @param {String} [value=""]
611
+ * @returns {DescribedDataFieldBuilder}
612
+ * @example abbreviation("P")
613
+ */this.abbreviation=function(t){return this.describedField.abbreviation=e(t,""),this},/**
614
+ * Sets the optional path to an image resource.
615
+ *
616
+ * @function
617
+ * @param {String} [value=""]
618
+ * @returns {DescribedDataFieldBuilder}
619
+ * @example image("img/product.png")
620
+ */this.image=function(t){return this.describedField.image=e(t,""),this},/**
621
+ * Sets the index as an array of numbers containing the splitted array indexes of the source field.
622
+ * Example: "responses[2].hits.hits[4]._source.name" will have an index of [2,4].
623
+ *
624
+ * @function
625
+ * @param {number[]} [value=[]]
626
+ * @returns {DescribedDataFieldBuilder}
627
+ * @example index([2,4])
628
+ */this.index=function(e){return this.describedField.index=null==e?[]:e,this},/**
629
+ * Sets the group names as an array of strings containing the names of the dynamically added properties,
630
+ * that contain an array of {@link module:described_field.DescribedDataField}-Objects.
631
+ *
632
+ * @function
633
+ * @param {string[]} [value=[]]
634
+ * @returns {DescribedDataFieldBuilder}
635
+ * @example groupNames(["summaries","details","options"])
636
+ */this.groupNames=function(e){return this.describedField.groupNames=null==e?[]:e,this},/**
637
+ * Sets the display name.
638
+ *
639
+ * @function
640
+ * @param {String} [value=""]
641
+ * @returns {DescribedDataFieldBuilder}
642
+ * @example displayName("Color")
643
+ */this.displayName=function(t){return this.describedField.displayName=e(t,""),this},/**
644
+ * Sets the (technical) field name.
645
+ *
646
+ * @function
647
+ * @param {String} [value=""]
648
+ * @returns {DescribedDataFieldBuilder}
649
+ * @example fieldName("color")
650
+ */this.fieldName=function(t){return this.describedField.fieldName=e(t,""),this},/**
651
+ * Sets the value/content of the field.
652
+ *
653
+ * @function
654
+ * @param {*} value
655
+ * @returns {DescribedDataFieldBuilder}
656
+ * @example value("darkblue")
657
+ */this.value=function(e){return this.describedField.value=e,this},/**
658
+ * Finalizes the settings and builds the {@link module:described_field.DescribedDataField}.
659
+ * @function
660
+ * @returns {module:described_field.DescribedDataField}
661
+ */this.build=function(){return this.describedField}})}(),/**
662
+ * Creates a new described data field with all properties of the original one except for dynamically added groups.
663
+ * @param {module:described_field.DescribedDataField} describedDataField
664
+ * @returns {module:described_field.DescribedDataField}
665
+ * @memberof module:described_field
666
+ */n.copyWithoutGroups=function(e){return new n.DescribedDataFieldBuilder().fromDescribedDataField(e).groupNames([]).build()},n.DescribedDataFieldGroup=/**
667
+ * Adds groups to {@link module:described_field.DescribedDataField}s. These groups are dynamically added properties
668
+ * that contain an array of sub fields of the same type {@link module:described_field.DescribedDataField}s.
669
+ *
670
+ * @param {module:described_field.DescribedDataField} dataField
671
+ * @constructs DescribedDataFieldGroup
672
+ * @alias module:described_field.DescribedDataFieldGroup
673
+ * @example new described_field.DescribedDataFieldGroup(field).addGroupEntry("details", detailField);
674
+ */function(e){this.dataField=e,/**
675
+ * Adds an entry to the given group. If the group does not exist, it will be created.
676
+ * @function
677
+ * @param {String} groupName name of the group to which the entry will be added
678
+ * @param {module:described_field.DescribedDataField} describedField sub field that is added to the group
679
+ * @returns {DescribedDataFieldGroup}
680
+ */this.addGroupEntry=function(e,t){return this.addGroupEntries(e,[t]),this},/**
681
+ * Adds entries to the given group. If the group does not exist, it will be created.
682
+ * @function
683
+ * @param {String} groupName name of the group to which the entries will be added
684
+ * @param {module:described_field.DescribedDataField[]} describedFields sub fields that are added to the group
685
+ * @returns {DescribedDataFieldGroup}
686
+ */this.addGroupEntries=function(e,t){var i,r;if(!e||0===e.length||!t||0===t.length)return this;for(void 0===this.dataField[e]&&(this.dataField.groupNames.push(e),this.dataField[e]=[]),i=0;i<t.length;i+=1)r=t[i],this.dataField[e].push(r);return this}}}),r("cB1fX");//# sourceMappingURL=datarestructor.js.map
687
+
2
688
  //# sourceMappingURL=datarestructor.js.map