Initial commit. Compile package code
This commit is contained in:
commit
4f73f1802e
18 changed files with 9605 additions and 0 deletions
9
.babelrc
Normal file
9
.babelrc
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"presets": ["@babel/preset-env", "@babel/preset-react"],
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"@babel/plugin-proposal-class-properties",
|
||||||
|
{"loose": true}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
10
.editorconfig
Normal file
10
.editorconfig
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# Unix-style newlines with a newline ending every file
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
node_modules/
|
2
.idea/.gitignore
vendored
Normal file
2
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
42
.idea/deployment.xml
Normal file
42
.idea/deployment.xml
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="PublishConfigData">
|
||||||
|
<serverData>
|
||||||
|
<paths name="Service 1">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="cdn.smartclip-services">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="dev.smartclip.net">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="smx-stats">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
<paths name="tools@Service 1">
|
||||||
|
<serverdata>
|
||||||
|
<mappings>
|
||||||
|
<mapping local="$PROJECT_DIR$" web="/" />
|
||||||
|
</mappings>
|
||||||
|
</serverdata>
|
||||||
|
</paths>
|
||||||
|
</serverData>
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/mcf-objects.iml
Normal file
8
.idea/mcf-objects.iml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptSettings">
|
||||||
|
<option name="languageLevel" value="JSX" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/mcf-objects.iml" filepath="$PROJECT_DIR$/.idea/mcf-objects.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
1
.nvmrc
Normal file
1
.nvmrc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
v12.13.1
|
10
README.md
Normal file
10
README.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# MCF-Components-Lib
|
||||||
|
|
||||||
|
This library exports an unique method to render components using *React* and *Material-UI* through a javascript object where is placed all
|
||||||
|
the information needed.
|
||||||
|
|
||||||
|
The method is **render**
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
To install the library you can get the repository or install it as a dependency.
|
2
dist/mcf-objects.js
vendored
Normal file
2
dist/mcf-objects.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/mcf-objects.js.map
vendored
Normal file
1
dist/mcf-objects.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
9206
package-lock.json
generated
Normal file
9206
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
25
package.json
Normal file
25
package.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"name": "mcf-objects",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"description": "Library to create custom typed objects with custom types",
|
||||||
|
"main": "dist/mcf-objects.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "webpack-dev-server --open --config webpack.dev.js",
|
||||||
|
"dist": "webpack --config webpack.prod.js",
|
||||||
|
"test": "jest",
|
||||||
|
"test:watch": "jest --watch"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.7.5",
|
||||||
|
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
||||||
|
"@babel/preset-env": "^7.7.6",
|
||||||
|
"@babel/preset-react": "^7.7.4",
|
||||||
|
"babel-loader": "^8.0.6",
|
||||||
|
"jest": "^24.9.0",
|
||||||
|
"webpack": "^4.41.3",
|
||||||
|
"webpack-cli": "^3.3.10",
|
||||||
|
"webpack-dev-server": "^3.9.0",
|
||||||
|
"webpack-merge": "^4.2.2"
|
||||||
|
},
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
235
src/index.js
Normal file
235
src/index.js
Normal file
|
@ -0,0 +1,235 @@
|
||||||
|
// --== OBJECTS LIBRARY ==--
|
||||||
|
// ========================================
|
||||||
|
|
||||||
|
class MCF_Type {
|
||||||
|
constructor(definition){
|
||||||
|
this.definition = definition;
|
||||||
|
this.validations = {};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(value){
|
||||||
|
this.validate(value);
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
getValue(){
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
validate(value){
|
||||||
|
for (let validation in this.validations){
|
||||||
|
this.validations[validation](value, this.definition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class MCF_String extends MCF_Type {
|
||||||
|
constructor(definition){
|
||||||
|
super(definition);
|
||||||
|
this.addValidations();
|
||||||
|
}
|
||||||
|
|
||||||
|
addValidations(){
|
||||||
|
this.validations.type = function(value) {
|
||||||
|
if (typeof (value) !== "string") {
|
||||||
|
throw new Error(`MCF_String creation: the type of ${value} isn't "string"`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let param in this.definition){
|
||||||
|
switch (param) {
|
||||||
|
case 'maxLength':
|
||||||
|
this.validations.maxLength = function(value, definition){
|
||||||
|
if (value.length > definition.maxLength){
|
||||||
|
throw new Error(`MCF_String creation: the length of the string "${value}" is higher than the maximum defined: ${definition.maxLength}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'minLength':
|
||||||
|
this.validations.minLength = function(value, definition){
|
||||||
|
if (value.length < definition.minLength){
|
||||||
|
throw new Error(`MCF_String creation: the length of the string "${value}" is lower than the minimum defined: ${definition.minLength}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class MCF_Number extends MCF_Type{
|
||||||
|
constructor(definition){
|
||||||
|
super(definition);
|
||||||
|
this.addValidations();
|
||||||
|
}
|
||||||
|
|
||||||
|
addValidations(){
|
||||||
|
this.validations.type = function(value) {
|
||||||
|
if (typeof (value) !== "number") {
|
||||||
|
throw new Error(`MCF_Number creation: the type of the value ${value} isn't "number"`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let param in this.definition){
|
||||||
|
switch (param) {
|
||||||
|
case 'max':
|
||||||
|
this.validations.max = function(value, definition){
|
||||||
|
if (value > definition.max){
|
||||||
|
throw new Error(`MCF_Number creation: the value ${value} is higher than the maximum defined: ${definition.maxLength}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'min':
|
||||||
|
this.validations.min = function(value, definition){
|
||||||
|
if (value < definition.min){
|
||||||
|
throw new Error(`MCF_Number creation: the value ${value} is lower than the minimum defined: ${definition.minLength}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class MCF_Boolean extends MCF_Type{
|
||||||
|
constructor(definition){
|
||||||
|
super(definition);
|
||||||
|
this.addValidations();
|
||||||
|
}
|
||||||
|
|
||||||
|
addValidations(){
|
||||||
|
this.validations.type = function(value) {
|
||||||
|
if (typeof (value) !== "boolean") {
|
||||||
|
throw new Error(`MCF_Boolean creation: the type of the value ${value} isn't "boolean"`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class MCF_Array extends MCF_Type {
|
||||||
|
constructor(definition){
|
||||||
|
super(definition);
|
||||||
|
this.addValidations();
|
||||||
|
}
|
||||||
|
|
||||||
|
addValidations(){
|
||||||
|
this.validations.type = function(value) {
|
||||||
|
if (!Array.isArray(value)) {
|
||||||
|
throw new Error(`MCF_Array creation: the type of ${value} isn't "array"`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let param in this.definition){
|
||||||
|
switch (param) {
|
||||||
|
case 'maxLength':
|
||||||
|
this.validations.maxLength = function(value, definition){
|
||||||
|
if (value.length > definition.maxLength){
|
||||||
|
throw new Error(`MCF_Array creation: the length of the array "${value}" is higher than the maximum defined: ${definition.maxLength}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'minLength':
|
||||||
|
this.validations.minLength = function(value, definition){
|
||||||
|
if (value.length < definition.minLength){
|
||||||
|
throw new Error(`MCF_Array creation: the length of the array "${value}" is lower than the minimum defined: ${definition.minLength}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class MCF_Enum extends MCF_Type{
|
||||||
|
constructor(definition){
|
||||||
|
super(definition);
|
||||||
|
this.addValidations();
|
||||||
|
}
|
||||||
|
|
||||||
|
addValidations(){
|
||||||
|
this.validations.isAvailable = function(value, definition){
|
||||||
|
const valueIsAvailable = definition.availableValues.reduce(function(isAvailable, availableValue){
|
||||||
|
if (value === availableValue) return true;
|
||||||
|
return isAvailable;
|
||||||
|
}, false);
|
||||||
|
if (!valueIsAvailable){
|
||||||
|
throw new Error(`MCF_Enum creation: the value "${value}" isn't one of the next values, included in the field definition: ${definition.availableValues.toString()}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class MCF_TypeFactory {
|
||||||
|
static buildDefinedObject(definedObject) {
|
||||||
|
const objectDefinition = definedObject.getDefinition();
|
||||||
|
let fields = objectDefinition.fields;
|
||||||
|
let dictionary = {};
|
||||||
|
for (let field in fields) {
|
||||||
|
switch (fields[field]['TYPE']) {
|
||||||
|
case 'string':
|
||||||
|
dictionary[field] = new MCF_String(fields[field]);
|
||||||
|
break;
|
||||||
|
case 'number':
|
||||||
|
dictionary[field] = new MCF_Number(fields[field]);
|
||||||
|
break;
|
||||||
|
case 'boolean':
|
||||||
|
dictionary[field] = new MCF_Boolean(fields[field]);
|
||||||
|
break;
|
||||||
|
case 'enum':
|
||||||
|
dictionary[field] = new MCF_Enum(fields[field]);
|
||||||
|
break;
|
||||||
|
case 'array':
|
||||||
|
dictionary[field] = new MCF_Array(fields[field]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dictionary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class MCF_DefinedObject {
|
||||||
|
constructor(definition){
|
||||||
|
this.definition = definition;
|
||||||
|
this.validations = {};
|
||||||
|
this.fields = MCF_TypeFactory.buildDefinedObject(this);
|
||||||
|
this.setValue(definition.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
getDefinition(){
|
||||||
|
return this.definition;
|
||||||
|
}
|
||||||
|
|
||||||
|
getValue(){
|
||||||
|
let value = {};
|
||||||
|
for (let field in this.fields){
|
||||||
|
value[field] = this.fields[field].value;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(value){
|
||||||
|
for (let field in this.definition.fields){
|
||||||
|
if (value[field] === undefined || value === null){
|
||||||
|
if (this.definition.fields[field].required === true){
|
||||||
|
throw new Error(`The field ${field} is required`);
|
||||||
|
}
|
||||||
|
if (this.definition.fields[field].defaultValue !== undefined){
|
||||||
|
value[field] = this.definition.fields[field].defaultValue;
|
||||||
|
}
|
||||||
|
if (this.definition.fields[field].null === false){
|
||||||
|
throw new Error(`The field ${field} can't be undefined`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let field in value){
|
||||||
|
if (value[field] === undefined){
|
||||||
|
this.fields[field].value = undefined;
|
||||||
|
} else {
|
||||||
|
this.fields[field].setValue(value[field]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setPropertiesValue(value){
|
||||||
|
for (let field in value){
|
||||||
|
this.fields[field].setValue(value[field]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {MCF_DefinedObject as definedObject};
|
22
webpack.common.js
Normal file
22
webpack.common.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: './src/index.js',
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, 'dist'),
|
||||||
|
filename: 'mcf-objects.js',
|
||||||
|
library: 'mcfObjects',
|
||||||
|
libraryTarget: 'umd'
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx)$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
use: {
|
||||||
|
loader: 'babel-loader',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
10
webpack.dev.js
Normal file
10
webpack.dev.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
const merge = require('webpack-merge');
|
||||||
|
const common = require('./webpack.common.js');
|
||||||
|
|
||||||
|
module.exports = merge(common, {
|
||||||
|
mode: 'development',
|
||||||
|
devtool: 'inline-source-map',
|
||||||
|
devServer: {
|
||||||
|
contentBase: './dist',
|
||||||
|
},
|
||||||
|
});
|
7
webpack.prod.js
Normal file
7
webpack.prod.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
const merge = require('webpack-merge');
|
||||||
|
const common = require('./webpack.common.js');
|
||||||
|
|
||||||
|
module.exports = merge(common, {
|
||||||
|
mode: 'production',
|
||||||
|
devtool: 'source-map',
|
||||||
|
});
|
Loading…
Reference in a new issue