1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("dmein",[],e):"object"==typeof exports?exports.dmein=e():t.dmein=e()}(this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}r.r(e),r.d(e,"Table",(function(){return a})),r.d(e,"Nodule",(function(){return i})),r.d(e,"FilterNodule",(function(){return d})),r.d(e,"JoinNodule",(function(){return E})),r.d(e,"TransformNodule",(function(){return B})),r.d(e,"GroupByNodule",(function(){return U}));var a=function(){function t(e){var r=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.getProperties=function(){return{id:r.id,label:r.label,rows:r.rows,headers:r.headers,type:r.type,isValid:r.isValid}},this.export=function(){return r.rows},this.setRows=function(t){var e=r._validateRows(t);if("ERR"===e.status)throw e;Array.isArray(t)?r.rows=t:r.rows=[t]},this._assignProps=function(t){r.id=t.id,r.label=t.label,r.type="Table",r.isValid=!0,t.rows?r.setRows(t.rows):r.rows=[]},this._validateConstructionProps=function(t){var e={status:"ERR",error:{label:"Error Creating Table",messages:[]}};return t?(t.id||e.error.messages.push("No id on creation of Table"),t.label||e.error.messages.push("No label on creation of Table"),0===e.error.messages.length?{status:"OK"}:e):(e.error.messages.push("No props on creation of Table"),e)},this._validateRows=function(t){var e={status:"ERR",error:{label:"Error Creating Table",messages:[]}},r=[];0===(r=Array.isArray(t)?t:[t]).length&&e.error.messages.push("No Tables imported");for(var o=0;o<r.length;o++)"object"!==n(r[o])&&e.error.messages.push("row[".concat(o,"] is not an object"));return e.error.messages.length>0?e:{status:"OK"}};var o=this._validateConstructionProps(e);if("ERR"===o.status)throw o;this._assignProps(e)}var e,r,a;return e=t,(r=[{key:"headers",get:function(){var t=this.rows;if(!Array.isArray(t)||t.length<1)return[];var e=t.length,r=49;e<50&&(r=e);var n=t.slice(0,r).map((function(t){return Object.keys(t)})).flat();return Array.from(new Set(n))}}])&&o(e.prototype,r),a&&o(e,a),t}();var i=function t(e){var r=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.asTable=function(){if(!r.export)return null;try{return new a({id:r.id,label:r.label,rows:r.export()})}catch(t){throw t}},this.getProperties=function(){var t=[];return t=Array.isArray(r.tables)?0===r.tables.length?[]:r.tables.map((function(t){return t.getProperties()})):[],{id:r.id,label:r.label,type:r.type,tables:t,isValid:r.isValid}},this.importTables=function(t){console.log('Function importTables has been depricated, please use "setTables()"'),r.setTables(t)},this.setTables=function(t){var e=r._validateTables(t);if("ERR"===e.status)throw e;var n=[];n=Array.isArray(t)?t:[t],r.tables=n},this._assignProps=function(t){r.id=t.id,r.label=t.label,r.type="Nodule",r.isValid=!0,t.tables?r.setTables(t.tables):r.tables=[]},this._validateTables=function(t){var e={status:"ERR",error:{label:"Not all imported Tables are valid",messages:[]}},r=[];if(!t)return e.error.messages.push("No Tables imported"),e;r=Array.isArray(t)?t:[t];for(var n=0;n<r.length;n++)r[n].isValid||e.error.messages.push("Table[".concat(n,"] is not valid"));return 0===e.error.messages.length?{status:"OK"}:e},this._validateConstructionProps=function(t){var e={status:"ERR",error:{label:"Error Creating Node",messages:[]}};return t.id||e.error.messages.push("No id on creation of Node"),t.label||e.error.messages.push("No label on creation of Node"),0===e.error.messages.length?{status:"OK"}:e};var n=this._validateConstructionProps(e);if("ERR"===n.status)throw n;this._assignProps(e)},u={EQUAL:"EQUAL",GREATER:"GREATER",GREATEREQUAL:"GREATEREQUAL",LESSER:"LESSER",LESSEREQUAL:"LESSEREQUAL"};function s(t){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function c(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function f(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?c(Object(r),!0).forEach((function(e){l(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function l(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function p(t,e){return(p=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function y(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=h(t);if(e){var o=h(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return b(this,r)}}function b(t,e){return!e||"object"!==s(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function h(t){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var d=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&p(t,e)}(r,t);var e=y(r);function r(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,r),(n=e.call(this,t)).addFilter=function(t){var e=n._validateFilters(t);if("ERR"===e.status)throw e;n.filterParams=f(f({},n.filterParams),t)},n.setFilterType=function(t){var e=n._validateType(t);if("ERR"===e.status)throw e;n.filterType=t},n.export=function(){var t=n.tables.map((function(t){return t.export()})).flat();return n._createFilterMethods().forEach((function(e){t=t.filter(e)})),t},n._assignProps=function(t){n.filterParams=t.filterParams||{},t.filterType&&n.setFilterType(t.filterType)},n._createFilterMethods=function(){var t=n._validateType(n.filterType);if("OK"!==t.status)throw t;var e=[],r=function(t){var r={};n.filterType===u.EQUAL?r=function(e){return e[t]===n.filterParams[t]}:n.filterType===u.GREATER?r=function(e){return e[t]>n.filterParams[t]}:n.filterType===u.GREATEREQUAL?r=function(e){return e[t]>=n.filterParams[t]}:n.filterType===u.LESSER?r=function(e){return e[t]<n.filterParams[t]}:n.filterType===u.LESSEREQUAL&&(r=function(e){return e[t]<=n.filterParams[t]}),e.push(r)};for(var o in n.filterParams)r(o);return e},n._validateFilters=function(t){var e={status:"ERR",error:{label:"Filter Parameter are not valid",messages:[]}};if("object"!==s(t)){var r=s(t);e.error.messages.push("Filter was of type ".concat(r," should be an object"))}return e.error.messages.length>0?e:{status:"OK"}},n._validateType=function(t){var e={status:"ERR",error:{label:"Filter Type is not valid",messages:[]}};return Object.values(u).indexOf(t)<0&&e.error.messages.push("Type must be one of: ".concat(Object.keys(u))),e.error.messages.length>0?e:{status:"OK"}},n._assignProps(t),n}return r}(i);function m(t){return(m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function v(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function g(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?v(Object(r),!0).forEach((function(e){O(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function O(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function w(t,e){return(w=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function P(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=R(t);if(e){var o=R(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return j(this,r)}}function j(t,e){return!e||"object"!==m(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function R(t){return(R=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var E=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&w(t,e)}(r,t);var e=P(r);function r(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,r),(n=e.call(this,t)).export=function(){var t=n.tables.find((function(t){return t.label===n.baseTableLabel})).export(),e=n.tables.filter((function(t){return t.label!==n.baseTableLabel}));return n.joinParams.map((function(r){var n=e.find((function(t){return t.label===r.foreignTable})).export();return t.map((function(t){var e=n.find((function(e){return t[r.primaryTableKey]===e[r.matchingKey]})),o={};for(var a in e)o["".concat(r.foreignTable,"::").concat(a)]=e[a];return g(g({},t),o)}))}))[0]},n.setJoinBy=function(t){var e=n._validateJoinBy(t);if("ERR"===e.status)throw e;n.baseTableLabel=t.baseTableLabel,n.joinParams=t.joinParams},n._assignProps=function(t){t.joinBy&&n.setJoinBy(t.joinBy)},n._validateJoinBy=function(t){var e={status:"ERR",error:{label:"JoinBy Parameters are not valid",messages:[]}},r=t.baseTableLabel,n=t.joinParams;if(r||e.error.messages.push("No baseTableLabel provided"),!Array.isArray(n)){var o=m(n);return e.error.messages.push("Keys was of type ".concat(o," should be an array")),e}for(var a=0;a<n.length;a++)"object"!==m(n[a])&&e.error.messages.push("joinParams[".concat(a,"] is not an object"));return e.error.messages.length>0?e:{status:"OK"}},n._assignProps(t),n}return r}(i);function _(t){return(_="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function T(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,o=!1,a=void 0;try{for(var i,u=t[Symbol.iterator]();!(n=(i=u.next()).done)&&(r.push(i.value),!e||r.length!==e);n=!0);}catch(t){o=!0,a=t}finally{try{n||null==u.return||u.return()}finally{if(o)throw a}}return r}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return S(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return S(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function A(t,e){return(A=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function x(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=L(t);if(e){var o=L(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return N(this,r)}}function N(t,e){return!e||"object"!==_(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function L(t){return(L=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var B=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&A(t,e)}(r,t);var e=x(r);function r(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,r),(n=e.call(this,t)).export=function(){return n.tables.map((function(t){return t.export()})).flat().map((function(t){for(var e={},r=0,o=Object.entries(n.structure);r<o.length;r++){var a=T(o[r],2),i=a[0];e[a[1]]=t[i]}return e}))},n.setStructure=function(t){var e=n._validateStructureProps(t);if("ERR"===e.status)throw e;n.structure=t},n._assignProps=function(t){t.structure&&n.setStructure(t.structure)},n._validateStructureProps=function(t){var e={status:"ERR",error:{label:"Ptructure Parameters are not valid",messages:[]}};if(!t)return e.error.messages.push("No structure provided"),e;for(var r in t)"string"!=typeof t[r]&&e.error.messages.push("Key [".concat(t,"] is not a String"));return e.error.messages.length>0?e:{status:"OK"}},n._assignProps(t),n}return r}(i);function D(t){return(D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function V(t,e){return(V=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function C(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=G(t);if(e){var o=G(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return K(this,r)}}function K(t,e){return!e||"object"!==D(e)&&"function"!=typeof e?F(t):e}function F(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function G(t){return(G=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var U=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&V(t,e)}(r,t);var e=C(r);function r(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,r),(n=e.call(this,t)).asTable=function(){var t=n.export(),e=[];for(var r in t){var o={id:"".concat(n.id,"-").concat(r),label:"".concat(n.label," by ").concat(r),rows:t[r]},i=new a(o);e.push(i)}return e},n.export=function(){var t=F(n).groupByValue;return n.tables.map((function(t){return t.export()})).flat().reduce((function(e,r){var n=r[t];return e[n]=e[n]||[],e[n].push(r),e}),{})},n.setGroupByValue=function(t){var e=n._validateGroupByValue(t);if("ERR"===e.status)throw e;n.groupByValue=t},n._assignProps=function(t){t.groupByValue&&n.setGroupByValue(t.groupByValue)},n._validateGroupByValue=function(t){if("string"==typeof t)return{status:"OK"};var e=D(t);[].push("GroupBy value was of type ".concat(e,", should be a string"))},n._assignProps(t),n}return r}(i);e.default={Table:a,Nodule:i,FilterNodule:d,JoinNodule:E,TransformNodule:B,GroupByNodule:U}}])})); |