From 22affbdfe1bd9639cd176a65d80aafe82e6f5bc4 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Date: Thu, 9 Sep 2021 16:14:27 +0200 Subject: [PATCH] Add dist directory --- .gitignore | 1 - dist/mcf-objects.js | 2 ++ dist/mcf-objects.js.map | 1 + src/index.js | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 dist/mcf-objects.js create mode 100644 dist/mcf-objects.js.map diff --git a/.gitignore b/.gitignore index 400900c..6bdbe62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /node_modules/ /.idea/ -/dist/ \ No newline at end of file diff --git a/dist/mcf-objects.js b/dist/mcf-objects.js new file mode 100644 index 0000000..47293a3 --- /dev/null +++ b/dist/mcf-objects.js @@ -0,0 +1,2 @@ +!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(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},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 r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},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 r(t,e){for(var n=0;n MCF_Array validation: 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-Objects ==> MCF_Array validation: 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 MCF_Array validation: the length of the array "'.concat(t,'" is lower than the minimum defined: ').concat(e.minLength))}}}}])&&c(e.prototype,n),r&&c(e,r),i}(o);function y(t){return(y="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 p(t,e){for(var n=0;n MCF_Boolean creation: the type of the value ".concat(t,' isn\'t "boolean"'))}}}])&&p(e.prototype,n),r&&p(e,r),i}(o);function O(t){return(O="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 w(t,e){for(var n=0;n MCF_Enum validation: the value "'.concat(t,"\" isn't one of the next values, included in the field definition: ").concat(e.availableValues.toString()))}}}])&&w(e.prototype,n),r&&w(e,r),i}(o);function E(t){return(E="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 x(t,e){for(var n=0;n MCF_Number validation: 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-Objects ==> MCF_Number validation: the value ".concat(t," is higher than the maximum defined: ").concat(e.max))};break;case"min":this.validations.min=function(t,e){if(t MCF_Number validation: the value ".concat(t," is lower than the minimum defined: ").concat(e.min))}}}}])&&x(e.prototype,n),r&&x(e,r),i}(o);function F(t){return(F="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){for(var n=0;n MCF_String validation: 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-Objects ==> MCF_String validation: 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 MCF_String validation: the length of the string "'.concat(t,'" is lower than the minimum defined: ').concat(e.minLength))}}}}])&&V(e.prototype,n),r&&V(e,r),i}(o);function N(t,e){for(var n=0;n The object type ".concat(n[o].TYPE," does not exist. Check the field definition in the object definition ").concat(e))}return r}}],(n=null)&&N(e.prototype,n),r&&N(e,r),t}();function J(t,e){for(var n=0;n MCF_Array validation: the type of ${value} isn't \"array\"`)\n }\n }\n\n for (const param in this.definition) {\n switch (param) {\n case 'maxLength':\n this.validations.maxLength = function(value, definition) {\n if (value.length > definition.maxLength) {\n throw new Error(`MCF-Objects ==> MCF_Array validation: the length of the array \"${value}\" is higher than the maximum defined: ${definition.maxLength}`)\n }\n }\n break\n case 'minLength':\n this.validations.minLength = function(value, definition) {\n if (value.length < definition.minLength) {\n throw new Error(`MCF-Objects ==> MCF_Array validation: the length of the array \"${value}\" is lower than the minimum defined: ${definition.minLength}`)\n }\n }\n break\n }\n }\n }\n}\n","import MCF_BaseType from './base'\n\n\n\nexport default class MCF_Boolean extends MCF_BaseType {\n constructor(definition) {\n super(definition)\n this.addValidations()\n }\n\n addValidations() {\n this.validations.type = function(value) {\n if (typeof(value) !== 'boolean') {\n throw new Error(`MCF-Objects ==> MCF_Boolean creation: the type of the value ${value} isn't \"boolean\"`)\n }\n }\n }\n}\n","import MCF_BaseType from './base'\n\n\n\nexport default class MCF_Enum extends MCF_BaseType {\n constructor(definition) {\n super(definition)\n this.addValidations()\n }\n\n addValidations() {\n this.validations.isAvailable = function(value, definition) {\n const valueIsAvailable = definition.availableValues.reduce(function(isAvailable, availableValue) {\n if (value === availableValue) return true\n return isAvailable\n }, false)\n if (!valueIsAvailable) {\n throw new Error(`MCF-Objects ==> MCF_Enum validation: the value \"${value}\" isn't one of the next values, included in the field definition: ${definition.availableValues.toString()}`)\n }\n }\n }\n}\n","import MCF_BaseType from './base'\n\n\nexport default class MCF_Number extends MCF_BaseType {\n constructor(definition) {\n super(definition)\n this.addValidations()\n }\n\n addValidations() {\n this.validations.type = function(value) {\n if (typeof(value) !== 'number') {\n throw new Error(`MCF-Objects ==> MCF_Number validation: the type of the value ${value} isn't \"number\"`)\n }\n }\n\n for (const param in this.definition) {\n switch (param) {\n case 'max':\n this.validations.max = function(value, definition) {\n if (value > definition.max) {\n throw new Error(`MCF-Objects ==> MCF_Number validation: the value ${value} is higher than the maximum defined: ${definition.max}`)\n }\n }\n break\n case 'min':\n this.validations.min = function(value, definition) {\n if (value < definition.min) {\n throw new Error(`MCF-Objects ==> MCF_Number validation: the value ${value} is lower than the minimum defined: ${definition.min}`)\n }\n }\n break\n }\n }\n }\n}\n","import MCF_BaseType from './base'\n\n\n\nexport default class MCF_String extends MCF_BaseType {\n constructor(definition) {\n super(definition)\n this.addValidations()\n }\n\n addValidations() {\n this.validations.type = function(value) {\n if (typeof(value) !== 'string') {\n throw new Error(`MCF-Objects ==> MCF_String validation: the type of ${value} isn't \"string\"`)\n }\n }\n\n for (const param in this.definition) {\n switch (param) {\n case 'maxLength':\n this.validations.maxLength = function(value, definition) {\n if (value.length > definition.maxLength) {\n throw new Error(`MCF-Objects ==> MCF_String validation: the length of the string \"${value}\" is higher than the maximum defined: ${definition.maxLength}`)\n }\n }\n break\n case 'minLength':\n this.validations.minLength = function(value, definition) {\n if (value.length < definition.minLength) {\n throw new Error(`MCF-Objects ==> MCF_String validation: the length of the string \"${value}\" is lower than the minimum defined: ${definition.minLength}`)\n }\n }\n break\n }\n }\n }\n}\n","import MCF_Array from './array'\nimport MCF_Boolean from './boolean'\nimport MCF_Enum from './enum'\nimport MCF_Number from './number'\nimport MCF_String from './string'\n\n\n\nexport default class MCF_TypeFactory {\n static buildDefinedObject(definedObject) {\n const objectDefinition = definedObject.getDefinition()\n const fields = objectDefinition.fields\n const dictionary = {}\n for (const field in fields) {\n switch (fields[field]['TYPE']) {\n case 'array':\n dictionary[field] = new MCF_Array(fields[field])\n break\n case 'boolean':\n dictionary[field] = new MCF_Boolean(fields[field])\n break\n case 'enum':\n dictionary[field] = new MCF_Enum(fields[field])\n break\n case 'number':\n dictionary[field] = new MCF_Number(fields[field])\n break\n case 'string':\n dictionary[field] = new MCF_String(fields[field])\n break\n default:\n throw new Error(`MCF-Objects ==> The object type ${fields[field]['TYPE']} does not exist. Check the field definition in the object definition ${objectDefinition}`)\n }\n }\n return dictionary\n }\n}\n","import MCF_TypeFactory from './types/typeFactory'\n\n\n\nexport default class MCF_DefinedObject {\n constructor(definition) {\n this.definition = definition\n this.validations = {}\n this.fields = MCF_TypeFactory.buildDefinedObject(this)\n this.validateValue(definition.values)\n this.setValue(definition.values)\n }\n\n getValue() {\n const value = {}\n for (const field in this.fields) {\n value[field] = this.fields[field].value\n }\n return value\n }\n\n setValue(value) {\n for (const valueKey in value) {\n if (value[valueKey] === undefined) {\n this.fields[valueKey].value = undefined\n } else {\n if (this.fields[valueKey] === undefined) {\n throw new Error(`The field ${valueKey} doesn't exist in the current DefinedObject: ${JSON.stringify(Object.keys(this.fields), null, 2)}`)\n }\n this.fields[valueKey].setValue(value[valueKey])\n }\n }\n }\n\n getDefinition() {\n return this.definition\n }\n\n validateValue(value) {\n for (const field in this.definition.fields) {\n if (value[field] === undefined || value === null) {\n if (this.definition.fields[field].required === true) {\n throw new Error(`The field ${field} is required`)\n }\n if (this.definition.fields[field].defaultValue !== undefined) {\n value[field] = this.definition.fields[field].defaultValue\n }\n if (this.definition.fields[field].null === false) {\n throw new Error(`The field ${field} can't be undefined`)\n }\n }\n }\n }\n\n updateArrayField(field, arrayItem, mustBeIncluded) {\n const fieldArray = this.getValue()[field] || []\n\n if (!fieldArray.includes(arrayItem) && mustBeIncluded) fieldArray.push(arrayItem)\n if (fieldArray.includes(arrayItem) && !mustBeIncluded) fieldArray.splice(fieldArray.indexOf(arrayItem), 1)\n\n const newValue = {}\n newValue[field] = fieldArray\n this.setValue(newValue)\n }\n}\n","import MCF_DefinedObject from '../definedObject'\n\n\n\nconst fileFieldsDefition = {\n name: { TYPE: 'string', required: true },\n extension: { TYPE: 'string' },\n mimeType: { TYPE: 'string' },\n content: { TYPE: 'string', defaultValue: '' },\n}\n\nexport default class MCF_File extends MCF_DefinedObject {\n constructor(definition) {\n super({\n fields: { ...fileFieldsDefition, ...definition.fields },\n values: definition.values ? definition.values : definition,\n })\n }\n}\n"],"sourceRoot":""} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 5b7c0d5..871fc76 100644 --- a/src/index.js +++ b/src/index.js @@ -7,6 +7,7 @@ import MCF_DefinedObject from './definedObject' import MCF_File from './objects/file' + export { MCF_DefinedObject as DefinedObject, MCF_File as File,