mcf-objects/dist/mcf-objects.js
2020-10-19 18:02:44 +02:00

2 lines
No EOL
8.4 KiB
JavaScript

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mcfObjects=e():t.mcfObjects=e()}(window,(function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function r(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach((function(e){o(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t){return(a="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 u(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&&c(t,e)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function f(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 n,i=s(t);if(e){var r=s(this).constructor;n=Reflect.construct(i,arguments,r)}else n=i.apply(this,arguments);return l(this,n)}}function l(t,e){return!e||"object"!==a(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 s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function h(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function d(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function v(t,e,n){return e&&d(t.prototype,e),n&&d(t,n),t}n.r(e),n.d(e,"definedObject",(function(){return j})),n.d(e,"mcfFile",(function(){return P}));var y=function(){function t(e){h(this,t),this.definition=e,this.validations={}}return v(t,[{key:"setValue",value:function(t){this.validate(t),this.value=t}},{key:"getValue",value:function(){return this.value}},{key:"validate",value:function(t){for(var e in this.validations)this.validations[e](t,this.definition)}}]),t}(),p=function(t){u(n,t);var e=f(n);function n(t){var i;return h(this,n),(i=e.call(this,t)).addValidations(),i}return v(n,[{key:"addValidations",value:function(){for(var t in this.validations.type=function(t){if("string"!=typeof t)throw new Error("MCF_String creation: the type of ".concat(t,' isn\'t "string"'))},this.definition)switch(t){case"maxLength":this.validations.maxLength=function(t,e){if(t.length>e.maxLength)throw new Error('MCF_String creation: the length of the string "'.concat(t,'" is higher than the maximum defined: ').concat(e.maxLength))};break;case"minLength":this.validations.minLength=function(t,e){if(t.length<e.minLength)throw new Error('MCF_String creation: the length of the string "'.concat(t,'" is lower than the minimum defined: ').concat(e.minLength))}}}}]),n}(y),b=function(t){u(n,t);var e=f(n);function n(t){var i;return h(this,n),(i=e.call(this,t)).addValidations(),i}return v(n,[{key:"addValidations",value:function(){for(var t in this.validations.type=function(t){if("number"!=typeof t)throw new Error("MCF_Number creation: the type of the value ".concat(t,' isn\'t "number"'))},this.definition)switch(t){case"max":this.validations.max=function(t,e){if(t>e.max)throw new Error("MCF_Number creation: the value ".concat(t," is higher than the maximum defined: ").concat(e.max))};break;case"min":this.validations.min=function(t,e){if(t<e.min)throw new Error("MCF_Number creation: the value ".concat(t," is lower than the minimum defined: ").concat(e.min))}}}}]),n}(y),m=function(t){u(n,t);var e=f(n);function n(t){var i;return h(this,n),(i=e.call(this,t)).addValidations(),i}return v(n,[{key:"addValidations",value:function(){this.validations.type=function(t){if("boolean"!=typeof t)throw new Error("MCF_Boolean creation: the type of the value ".concat(t,' isn\'t "boolean"'))}}}]),n}(y),g=function(t){u(n,t);var e=f(n);function n(t){var i;return h(this,n),(i=e.call(this,t)).addValidations(),i}return v(n,[{key:"addValidations",value:function(){for(var t in this.validations.type=function(t){if(!Array.isArray(t))throw new Error("MCF_Array creation: the type of ".concat(t,' isn\'t "array"'))},this.definition)switch(t){case"maxLength":this.validations.maxLength=function(t,e){if(t.length>e.maxLength)throw new Error('MCF_Array creation: the length of the array "'.concat(t,'" is higher than the maximum defined: ').concat(e.maxLength))};break;case"minLength":this.validations.minLength=function(t,e){if(t.length<e.minLength)throw new Error('MCF_Array creation: the length of the array "'.concat(t,'" is lower than the minimum defined: ').concat(e.minLength))}}}}]),n}(y),w=function(t){u(n,t);var e=f(n);function n(t){var i;return h(this,n),(i=e.call(this,t)).addValidations(),i}return v(n,[{key:"addValidations",value:function(){this.validations.isAvailable=function(t,e){if(!e.availableValues.reduce((function(e,n){return t===n||e}),!1))throw new Error('MCF_Enum creation: the value "'.concat(t,"\" isn't one of the next values, included in the field definition: ").concat(e.availableValues.toString()))}}}]),n}(y),O=function(){function t(){h(this,t)}return v(t,null,[{key:"buildDefinedObject",value:function(t){var e=t.getDefinition().fields,n={};for(var i in e)switch(e[i].TYPE){case"string":n[i]=new p(e[i]);break;case"number":n[i]=new b(e[i]);break;case"boolean":n[i]=new m(e[i]);break;case"enum":n[i]=new w(e[i]);break;case"array":n[i]=new g(e[i])}return n}}]),t}(),j=function(){function t(e){h(this,t),this.definition=e,this.validations={},this.fields=O.buildDefinedObject(this),this.validateValue(e.value),this.setValue(e.value)}return v(t,[{key:"getDefinition",value:function(){return this.definition}},{key:"getValue",value:function(){var t={};for(var e in this.fields)t[e]=this.fields[e].value;return t}},{key:"validateValue",value:function(t){for(var e in this.definition.fields)if(void 0===t[e]||null===t){if(!0===this.definition.fields[e].required)throw new Error("The field ".concat(e," is required"));if(void 0!==this.definition.fields[e].defaultValue&&(t[e]=this.definition.fields[e].defaultValue),!1===this.definition.fields[e].null)throw new Error("The field ".concat(e," can't be undefined"))}}},{key:"setValue",value:function(t){for(var e in t)void 0===t[e]?this.fields[e].value=void 0:this.fields[e].setValue(t[e])}},{key:"setPropertiesValue",value:function(t){for(var e in t)this.fields[e].setValue(t[e])}}]),t}(),x={filename:{TYPE:"string"},extension:{TYPE:"string"},mimeType:{TYPE:"string"},path:{TYPE:"string"},content:{TYPE:"string"}},P=function(t){u(n,t);var e=f(n);function n(t){h(this,n);var i=t.fields?t.fields:{},o=t.value?t.value:t;return e.call(this,{fields:r(r({},x),i),value:o})}return n}(j)}])}));
//# sourceMappingURL=mcf-objects.js.map