2 lines
No EOL
7.6 KiB
JavaScript
2 lines
No EOL
7.6 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){return(i="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 r(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&&o(t,e)}function o(t,e){return(o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(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=c(t);if(e){var r=c(this).constructor;n=Reflect.construct(i,arguments,r)}else n=i.apply(this,arguments);return u(this,n)}}function u(t,e){return!e||"object"!==i(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 c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function f(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function l(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 s(t,e,n){return e&&l(t.prototype,e),n&&l(t,n),t}n.r(e),n.d(e,"definedObject",(function(){return g})),n.d(e,"mcfFile",(function(){return x}));var h=function(){function t(e){f(this,t),this.definition=e,this.validations={}}return s(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}(),d=function(t){r(n,t);var e=a(n);function n(t){var i;return f(this,n),(i=e.call(this,t)).addValidations(),i}return s(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}(h),v=function(t){r(n,t);var e=a(n);function n(t){var i;return f(this,n),(i=e.call(this,t)).addValidations(),i}return s(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}(h),y=function(t){r(n,t);var e=a(n);function n(t){var i;return f(this,n),(i=e.call(this,t)).addValidations(),i}return s(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}(h),m=function(t){r(n,t);var e=a(n);function n(t){var i;return f(this,n),(i=e.call(this,t)).addValidations(),i}return s(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}(h),p=function(t){r(n,t);var e=a(n);function n(t){var i;return f(this,n),(i=e.call(this,t)).addValidations(),i}return s(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}(h),b=function(){function t(){f(this,t)}return s(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 d(e[i]);break;case"number":n[i]=new v(e[i]);break;case"boolean":n[i]=new y(e[i]);break;case"enum":n[i]=new p(e[i]);break;case"array":n[i]=new m(e[i])}return n}}]),t}(),g=function(){function t(e){f(this,t),this.definition=e,this.validations={},this.fields=b.buildDefinedObject(this),this.setValue(e.value)}return s(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:"setValue",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"))}for(var n in t)void 0===t[n]?this.fields[n].value=void 0:this.fields[n].setValue(t[n])}},{key:"setPropertiesValue",value:function(t){for(var e in t)this.fields[e].setValue(t[e])}}]),t}(),w={filename:{TYPE:"string",required:!0},extension:{TYPE:"string",required:!0},path:{TYPE:"string",required:!0},content:{TYPE:"string"}},x=function(t){r(n,t);var e=a(n);function n(t){return f(this,n),e.call(this,{fields:w,value:t})}return n}(g)}])}));
|
|
//# sourceMappingURL=mcf-objects.js.map
|