<commit_before>{
  "name": "Export-class",
  "master": false,
  "version": "0.0.1",
  "description": "",
  "schemas": {
    "v1dfff1f04618899": {
      "_id": "v1dfff1f04618899",
      "_name": "Export",
      "_inherit": ["_Component"],
      "toJSON": "method",
      "toHTML": "method",
      "toJavaScript": "method",
      "toNode": "method",
      "toGraphviz": "method"
    }
  },
  "models": {
    "v1ca291072418fa4": {
      "_id": "v1ca291072418fa4",
      "_name": "Export",
      "toJSON": {
        "params": [
          {
            "name": "isMaster",
            "type": "boolean",
            "mandatory": false,
            "default": true
          }
        ],
        "result": "string"
      },
      "toHTML": {
        "params": [
          {
            "name": "logLevel",
            "type": "string",
            "mandatory": false,
            "default": "info"
          }
        ],
        "result": "string"
      },
      "toNode": {
        "params": [
          {
            "name": "logLevel",
            "type": "string",
            "mandatory": false,
            "default": "info"
          }
        ],
        "result": "string"
      },
      "toJavaScript": {
        "params": [
          {
            "name": "logLevel",
            "type": "string",
            "mandatory": false,
            "default": "info"
          }
        ],
        "result": "string"
      },
      "toGraphviz": {
        "description": "",
        "params": [
          {
            "name": "diagramType",
            "description": "",
            "type": "string",
            "mandatory": false,
            "default": "class"
          }
        ],
        "result": "string"
      }
    }
  },
  "behaviors": {
    "p14b27128f61643e": {
      "_id": "p14b27128f61643e",
      "component": "Export",
      "state": "toJSON",
      "action": "function toJSON(isMaster) {\n  var system = this.require('db').collections().System.find({\n    '_id': this.require('factory').system().id()\n  })[0];\n  system = JSON.parse(JSON.stringify(system));\n  delete system.classInfo;\n\n  system = JSON.parse(JSON.stringify(system));\n\n  if (isMaster) {\n    system.master = true;\n  } else {\n    system.master = false;\n  }\n\n  return JSON.stringify(system);\n}",
      "useCoreAPI": false,
      "core": false
    },
    "g131c91154e14849": {
      "_id": "g131c91154e14849",
      "component": "Export",
      "state": "toHTML",
      "action": "function toHTML(logLevel) {\n  var system = this.require('db').collections().System.find({\n    '_id': this.require('factory').system().id()\n  })[0];\n  system = JSON.parse(JSON.stringify(system));\n  delete system.classInfo;\n\n  var source = this.require('export-app.html').source();\n\n  source = source\n    .replace(/{{name}}/g, this.require('factory').system().name())\n    .replace(/{{logLevel}}/g, $('#designer-dialog-export-options-log-level-select').val())\n    .replace(/{{system}}/g, function (val) { return JSON.stringify(system) });\n\n  return source;\n}",
      "useCoreAPI": false,
      "core": false
    },
    "r11d81144f810201": {
      "_id": "r11d81144f810201",
      "component": "Export",
      "state": "toNode",
      "action": "function toNode(logLevel) {\n  var system = this.require('db').collections().System.find({\n    '_id': this.require('factory').system().id()\n  })[0];\n  system = JSON.parse(JSON.stringify(system));\n  delete system.classInfo;\n\n  var source = this.require('app.js').source();\n\n  source = source\n    .replace(/{{version}}/g, this.require('factory').system().version())\n    .replace(/{{description}}/g, this.require('factory').system().description().replace(/\\n/g, '\\n * '))\n    .replace(/{{name}}/g, this.require('factory').system().name())\n    .replace(/{{logLevel}}/g, $('#designer-dialog-export-options-log-level-select').val())\n    .replace(/{{system}}/g, JSON.stringify(system));\n\n  return source;\n}",
      "useCoreAPI": false,
      "core": false
    },
    "h14919197fb17aaf": {
      "_id": "h14919197fb17aaf",
      "component": "Export",
      "state": "toJavaScript",
      "action": "function toJavaScript(logLevel) {\n  var system = this.require('db').collections().System.find({\n    '_id': this.require('factory').system().id()\n  })[0];\n  system = JSON.parse(JSON.stringify(system));\n  delete system.classInfo;\n\n  var source = this.require('javascript-export.js').source();\n\n  source = source\n    .replace(/{{version}}/g, this.require('factory').system().version())\n    .replace(/{{description}}/g, this.require('factory').system().description().replace(/\\n/g, '\\n * '))\n    .replace(/{{name}}/g, this.require('factory').system().name())\n    .replace(/{{logLevel}}/g, $('#designer-dialog-export-options-log-level-select').val());\n\n  // SYSTEM\n\n  var confSystem = {};\n\n  confSystem._id = system._id;\n  confSystem.name = system.name;\n  confSystem.version = system.version;\n  confSystem.description = system.description;\n\n  source = source + '/**\\n';\n  source = source + ' * System ' + confSystem.name + '\\n';\n  source = source + ' * @system\\n';\n  source = source + ' */\\n';\n  source = source + 'runtime.system(' + JSON.stringify(confSystem, null, '\\t', 2) + ');\\n\\n';\n\n  // SCHEMA / MODEL / TYPE     \n  if (Object.keys(system.schemas).length > 0 || Object.keys(system.types).length > 0) {\n    source = source + '\\n// Schemas, models and types creation\\n\\n\\n';\n  }\n\n  var name = '';\n  var schemaSorted = [];\n  var schemaNameSorted = [];\n  var schemaName = {};\n\n  for (name in system.schemas) {\n    schemaSorted.push(system.schemas[name]);\n    schemaNameSorted.push(system.schemas[name]._name);\n    schemaName[system.schemas[name]._name] = system.schemas[name]._name;\n  }\n  schemaSorted.sort(function (schemaA, schemaB) {\n    return schemaA._name > schemaB._name;\n  });\n  schemaNameSorted.sort();\n\n  schemaSorted.forEach(function (schema) {\n    source = source + '/**\\n';\n    source = source + ' * Schema ' + schema._name + '\\n';\n    source = source + ' * @schema\\n';\n    source = source + ' */\\n';\n    source = source + 'runtime.require(\\'metamodel\\').schema(' + JSON.stringify(schema, null, '\\t', 2) + ');\\n\\n';\n  });\n\n  var modelSorted = [];\n  var modelNameSorted = [];\n  for (name in system.models) {\n    modelSorted.push(system.models[name]);\n    modelNameSorted.push(system.models[name]._name);\n  }\n  modelSorted.sort(function (modelA, modelB) {\n    return modelA._name > modelB._name;\n  });\n  modelNameSorted.sort();\n\n  modelSorted.forEach(function (model) {\n    source = source + '/**\\n';\n    source = source + ' * Model ' + model._name + '\\n';\n    source = source + ' * @model\\n';\n    source = source + ' */\\n';\n    source = source + 'runtime.require(\\'metamodel\\').model(' + JSON.stringify(model, null, '\\t', 2) + ');\\n\\n';\n  });\n\n  var typeSorted = [];\n  var typeNameSorted = [];\n  for (name in system.types) {\n    typeSorted.push(system.types[name]);\n    typeNameSorted.push(system.types[name].name);\n  }\n  typeSorted.sort(function (typeA, typeB) {\n    return typeA.name > typeB.name;\n  });\n  typeNameSorted.sort();\n\n  typeSorted.forEach(function (type) {\n    source = source + '/**\\n';\n    source = source + ' * Type ' + type.name + '\\n';\n    source = source + ' * @type\\n';\n    source = source + ' */\\n';\n    source = source + 'runtime.require(\\'metamodel\\').type(' + JSON.stringify(type, null, '\\t', 2) + ');\\n\\n';\n  });\n\n  if (Object.keys(system.schemas).length > 0 || Object.keys(system.models).length > 0 || Object.keys(system.types).length > 0) {\n    source = source + 'runtime.require(\\'metamodel\\').create();\\n\\n';\n  }\n\n  // COMPONENT   \n  if (Object.keys(system.components).length > 0) {\n    source = source + '\\n// Components creation\\n\\n\\n';\n  }\n  schemaNameSorted.forEach(function (collection) {\n    for (name in system.components[collection]) {\n      source = source + '/**\\n';\n      source = source + ' * Component ' + system.components[collection][name]._id + '\\n';\n      source = source + ' * @component\\n';\n      source = source + ' */\\n';\n      source = source + 'new (runtime.require(\\'' + collection + '\\'))(' + JSON.stringify(system.components[collection][name], null, '\\t', 2) + ');\\n\\n';\n    }\n  });\n\n  // BEHAVIOR   \n  if (Object.keys(system.behaviors).length > 0) {\n    source = source + '\\n// Behaviors creation\\n\\n\\n';\n  }\n\n  var behaviors = {};\n  var behaviorsComponentNameSorted = [];\n  var modelsByName = {};\n\n  for (name in system.behaviors) {\n    if (typeof behaviors[system.behaviors[name].component] === 'undefined') {\n      behaviors[system.behaviors[name].component] = [];\n    }\n    behaviors[system.behaviors[name].component].push(system.behaviors[name]);\n  }\n\n  behaviorsComponentNameSorted = Object.keys(behaviors);\n  behaviorsComponentNameSorted.sort();\n\n  var id = '';\n  for (id in system.models) {\n    modelsByName[system.models[id]._name] = system.models[id];\n  }\n\n  behaviorsComponentNameSorted.forEach(function forEach(componentName) {\n    var componentBehaviors = behaviors[componentName];\n\n    componentBehaviors.sort(function sort(behaviorA, behaviorB) {\n      return behaviorA.state > behaviorB.state;\n    });\n\n    if (componentBehaviors.length > 0) {\n      if (componentName === system._id) {\n        source = source + '// system behaviors\\n\\n';\n      } else {\n        source = source + '// ' + componentName + ' behaviors\\n\\n';\n      }\n    }\n\n    componentBehaviors.forEach(function forEach(behavior) {\n      var useCoreAPI = typeof behavior.useCoreAPI !== 'undefined' ? behavior.useCoreAPI : false;\n      var core = typeof behavior.core !== 'undefined' ? behavior.core : false;\n      var comp = '';\n      var behaviorParamDef = {};\n      var options = ');\\n\\n';\n\n      if (useCoreAPI && !core) {\n        options = ', true);\\n\\n';\n      }\n      if (useCoreAPI && core) {\n        options = ', true, true);\\n\\n';\n      }\n\n      source = source + '/**\\n';\n      source = source + ' * @method ' + behavior.state + '\\n';\n\n      if (modelsByName[behavior.component] && modelsByName[behavior.component][behavior.state] && modelsByName[behavior.component][behavior.state].params) {\n        modelsByName[behavior.component][behavior.state].params.forEach(function forEach(param) {\n          source = source + ' * @param {' + param.type + '} ' + param.name + '\\n';\n        });\n      }\n      if (modelsByName[behavior.component] && modelsByName[behavior.component][behavior.state] && modelsByName[behavior.component][behavior.state].result) {\n        source = source + ' * @returns {' + modelsByName[behavior.component][behavior.state].result + '} \\n';\n      }\n\n      source = source + ' */\\n';\n\n      switch (true) {\n        case behavior.component === system._id:\n          comp = 'runtime.system()';\n          break;\n        default:\n          comp = 'runtime.require(\\'' + behavior.component + '\\')';\n          break;\n      }\n\n      source = source + comp + '.on(\\'' + behavior.state + '\\', ' + behavior.action + options;\n    })\n  });\n\n  // START\n  source = source + '// Start the system\\n';\n  source = source + 'runtime.system().start();\\n';\n\n  return source;\n}",
      "useCoreAPI": false,
      "core": false
    },
    "e13c7916b1a15fc4": {
      "_id": "e13c7916b1a15fc4",
      "component": "Export",
      "state": "toGraphviz",
      "action": "function toGraphviz(diagramType) {\n  var schemas = this.require('factory').system().schemas();\n  var models = this.require('factory').system().models();\n  var types = this.require('factory').system().types();\n  var components = this.require('factory').system().components();\n  var inheritance = '';\n  var modelId = '';\n  var typeId = '';\n  var componentId = '';\n  var modelName = '';\n  var typeName = '';\n  var modelDescription = '';\n  var propName = '';\n  var propVal = '';\n  var propDef = '';\n  var attributes = '';\n  var methods = '';\n  var result = '';\n  var dependencies = '';\n  var instancesOf = '';\n  var links = '';\n  var collections = '';\n  var instances = '';\n  var that = this;\n  var keys = [];\n  var sortedKeys = {};\n  var generatedDiagram = '';\n  var parents = '';\n  var modelNames = [];\n  var modelDef = {};\n  var schemaDef = {};\n  var incoming = '';\n  var outgoing = '';\n  var edges = '';\n  var relationships = '';\n  var instancesRelation ='';\n  var kindToEdgeStyle = {\n    'normal': 'none',\n    'dependency': 'vee',\n    'composition': 'diamond',\n    'aggregation': 'odiamond'\n  };\n\n  callbackProp = function (param) {\n    var realType = param.type;\n    var isArray = false;\n\n    if (Array.isArray(param.type)) {\n      isArray = true;\n      realType = param.type[0];\n    }\n\n    if (that.require('factory').isModel(realType) && realType !== '_Component') {\n      if (isArray) {\n        params = params + param.name + ' : [' + realType + '], ';\n      } else {\n        params = params + param.name + ' : ' + realType + ', ';\n      }\n    } else {\n      if (['any', 'boolean', 'string', 'number', 'object', 'function', 'array', 'html', 'javascript', 'css', 'errorParam', 'json', 'text', 'date'].indexOf(realType) === -1 && realType !== '_Component') {\n        if (isArray) {\n          params = params + param.name + ' : [' + realType + '], ';\n        } else {\n          params = params + param.name + ' : ' + realType + ', ';\n        }\n      } else {\n        if (isArray) {\n          params = params + param.name + ' : [' + realType + '], ';\n        } else {\n          params = params + param.name + ' : ' + realType + ', ';\n        }\n      }\n    }\n  };\n\n  function _getReturnType(returnType) {\n    var result = '';\n    var realType = returnType;\n    var isArray = false;\n\n    if (Array.isArray(returnType)) {\n      isArray = true;\n      realType = returnType[0];\n    }\n\n    if (that.require('factory').isModel(realType) && realType !== '_Component' && realType !== '_ClassInfo') {\n      if (isArray) {\n        result = '[' + realType + ']';\n      } else {\n        result = realType;\n      }\n    } else {\n      if (['any', 'boolean', 'string', 'number', 'object', 'function', 'array', 'html', 'javascript', 'css', 'errorParam', 'json', 'text', 'date'].indexOf(realType) === -1 && realType !== '_Component' && realType !== '_ClassInfo') {\n        if (isArray) {\n          result = '[' + realType + ']';\n        } else {\n          result = realType;\n        }\n      } else {\n        if (isArray) {\n          result = '[' + realType + ']';\n        } else {\n          result = realType;\n        }\n      }\n    }\n    return result;\n  }\n\n  function _getModelId(name) {\n    var result = '',\n      id = '';\n\n    for (id in that.require('factory').system().models()) {\n      if (that.require('factory').system().models()[id]._name === name) {\n        result = id;\n        break;\n      }\n    }\n    return result;\n  }\n\n  function _isType(name) {\n    return typeof types[name] !== 'undefined';\n  }\n\n  function _clean(text) {\n    return text.replace(/\\{/g, '').replace(/\\}/g, '');\n  }\n\n  function _cleanName(text) {\n    return text.toString()\n              .replace(/\\./g, '')\n              .replace(/\\-/g, '');\n  }\n\n  function _cleanVal(text) {\n    var clean = JSON.stringify(text).replace(/\\\"/g, '\\'')\n      .replace(/\\./g, '\\\\.')\n      .replace(/\\-/g, '\\\\-')\n      .replace(/\\{/g, '\\\\{')\n      .replace(/\\}/g, '\\\\}')\n      .replace(/\\</g, '\\\\<')\n      .replace(/\\>/g, '\\\\>')\n      .replace(/\\\\n/g, '');\n\n    if (clean.length > 42) {\n      return clean.substring(0, 42) + '...';\n    } else {\n      return clean;\n    }\n  }\n\n  // COMPUTATION\n\n  switch (diagramType) {\n    case 'graph':\n\n      // create node\n      for (modelId in models) {\n\n        modelName = models[modelId]._name;\n        parents = this.require('factory').getParents(modelName);\n        if (modelName !== 'Nodes' && modelName !== 'Relationships' && parents.indexOf('Nodes') !== -1) {\n          modelNames.push(modelName);\n          modelDescription += '\\n\\n\\t' + modelName + ' [\\n\\t\\tlabel = ' + modelName + '\\n\\t]';\n        }\n      }\n\n      // create relationships\n      for (modelId in models) {\n\n        modelName = models[modelId]._name;\n        parents = this.require('factory').getParents(modelName);\n        modelDef = this.require('factory').getGeneratedModel(modelName);\n        if (modelName !== 'Nodes' && modelName !== 'Relationships' && parents.indexOf('Relationships') !== -1) {\n          incoming = modelDef.incoming.type;\n          outgoing = modelDef.outgoing.type;\n\n          edges += `\\n\\tedge [\n    headlabel = \"\"\n    taillabel = \"\"\n    fontsize = 5\n    label     = ${modelName}\n  ]`;\n\n          switch (true) {\n            case incoming === 'Nodes' && outgoing === 'Nodes':\n              modelNames.forEach(function (incoming) {\n                modelNames.forEach(function (outgoing) {\n                  edges += '\\n\\t' + _cleanName(incoming) + ' -> ' + _cleanName(outgoing) + '\\n';\n                });\n              });\n              break;\n            case incoming === 'Nodes' && outgoing !== 'Nodes':\n              modelNames.forEach(function (incoming) {\n                edges += '\\n\\t' + _cleanName(incoming) + ' -> ' + _cleanName(outgoing) + '\\n';\n              });\n              break;\n            case incoming !== 'Nodes' && outgoing !== 'Nodes':\n              edges += '\\n\\t' + _cleanName(incoming) + ' -> ' + _cleanName(outgoing) + '\\n';\n              break;\n            default:\n              break;\n          }\n        }\n      }\n\n      break;\n\n    case 'component':\n\n      // create instances\n      for (modelName in components) {\n        schemaDef = this.require('factory').getGeneratedSchema(modelName);\n        parents = this.require('factory').getParents(modelName);\n\n        for (componentId in components[modelName]) {\n          \n          if (modelName === 'Relationships' || parents.indexOf('Relationships') !== -1) {\n            instancesRelation += '\\n\\n\\t' + _cleanName(componentId) + ' [\\n\\t\\tlabel = \"{\\n\\t\\t\\t' + componentId + ' : ' + modelName + '|';\n          } else {\n            instances += '\\n\\n\\t' + _cleanName(componentId) + ' [\\n\\t\\tlabel = \"{\\n\\t\\t\\t' + componentId + ' : ' + modelName + '|';\n          }\n          attributes = '';\n          \n          keys = [];\n          sortedKeys = {};\n          \n           // get keys\n          for (propName in components[modelName][componentId]) {\n            keys.push(propName);\n          }\n          keys.sort();\n          \n          // sorted keys\n          keys.forEach(function(key) {\n            sortedKeys[key] = components[modelName][componentId][key];\n          }.bind(this));\n\n          for (var prop in sortedKeys) {\n            if (prop !== '_id') {\n              if (prop !== 'incoming' && prop !== 'outgoing') {\n                if (schemaDef[prop] && schemaDef[prop] === 'collection') {\n                  if (sortedKeys[prop].length > 0) {\n                    attributes += '\\n\\t\\t\\t' + prop + ' = [\\\\l' + sortedKeys[prop].map(function(item) { return _cleanVal(item)}).join(',\\\\l') + '\\\\l]\\\\l'; \n                  } else {\n                    attributes += '\\n\\t\\t\\t' + prop + ' = []\\\\l'; \n                  }\n                } else {\n                  attributes += '\\n\\t\\t\\t' + prop + ' = ' + _cleanVal(sortedKeys[prop]) + '\\\\l';\n                }\n              }\n              \n              if (schemaDef[prop] && (schemaDef[prop] === 'link' || schemaDef[prop] === 'collection')) {\n                if (sortedKeys[prop] !== '') {\n                \n                  switch(prop) {\n                    case 'incoming':\n                      relationships += '\\n\\t' + _cleanName(sortedKeys[prop]) + ' -> ' + _cleanName(componentId); \n                      break;\n                    case 'outgoing':\n                      relationships += '\\n\\t' + _cleanName(componentId) + ' -> ' + _cleanName(sortedKeys[prop]); \n                      break;\n                    default:\n                      if (Array.isArray(sortedKeys[prop])) {\n                        sortedKeys[prop].forEach(function(item) {\n                          dependencies += '\\n\\t' + _cleanName(componentId) + ' -> ' + _cleanName(item);  \n                        })\n                      } else {\n                        dependencies += '\\n\\t' + _cleanName(componentId) + ' -> ' + _cleanName(sortedKeys[prop]);\n                      }\n                      break;\n                  }\n                }\n              }\n            }\n          }\n\n          if (modelName === 'Relationships' || parents.indexOf('Relationships') !== -1) {\n            instancesRelation += attributes;\n            instancesRelation += '\\n\\t\\t}\"\\r\\t]';\n          } else {\n            instances += attributes;\n            instances += '\\n\\t\\t}\"\\r\\t]';\n          }\n        }\n      }\n      break;\n\n    case 'class':\n\n      // create model for types\n      for (typeId in types) {\n\n        // structure\n        if (types[typeId].schema) {\n          typeName = types[typeId].name;\n          modelDescription += '\\n\\n\\t' + typeName + ' [\\n\\t\\tlabel = \"{\\n\\t\\t\\t' + typeName + '|';\n\n          attributes = '';\n          keys = [];\n          sortedKeys = {};\n\n          // get keys\n          for (propName in types[typeId].schema) {\n            keys.push(propName);\n          }\n          keys.sort();\n\n          // sorted keys\n          keys.forEach(function (key) {\n            sortedKeys[key] = types[typeId].schema[key];\n          }.bind(this));\n\n          for (propName in sortedKeys) {\n            if (types[typeId].schema.hasOwnProperty(propName)) {\n              propDef = types[typeId].schema[propName];\n              attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propDef.type + '\\\\l';\n              if (_isType(propDef.type)) {\n                dependencies += '\\n\\t' + typeName + ' -> ' + propDef.type;\n              }\n            }\n          }\n\n          modelDescription += _clean(attributes);\n          modelDescription += '\\n\\t\\t}\"\\r\\t]';\n        }\n\n        // enumeration\n        if (types[typeId].value) {\n          typeName = types[typeId].name;\n          modelDescription += '\\n\\n\\t' + typeName + ' [\\n\\t\\tlabel = \"{\\n\\t\\t\\t\\\\<\\\\<enumeration\\\\>\\\\>\\\\l' + typeName + '|';\n\n          attributes = '';\n\n          types[typeId].value.forEach(function (enumValue) {\n            attributes += '\\n\\t\\t\\t' + enumValue + '\\\\l';\n          });\n\n          modelDescription += _clean(attributes);\n          modelDescription += '\\n\\t\\t}\"\\r\\t]';\n        }\n      }\n\n      // create model\n      for (modelId in models) {\n\n        modelName = models[modelId]._name;\n        modelDescription += '\\n\\n\\t' + modelName + ' [\\n\\t\\tlabel = \"{\\n\\t\\t\\t' + modelName + '|';\n\n        attributes = '';\n        methods = '';\n        keys = [];\n        sortedKeys = {};\n\n        // get keys\n        for (propName in models[modelId]) {\n          keys.push(propName);\n        }\n        keys.sort();\n\n        // sorted keys\n        keys.forEach(function (key) {\n          sortedKeys[key] = models[modelId][key];\n        }.bind(this));\n\n        for (propName in sortedKeys) {\n          if (models[modelId].hasOwnProperty(propName)) {\n            propVal = models[modelId][propName];\n\n            switch (true) {\n              case typeof propVal.type !== 'undefined':\n                if (!Array.isArray(propVal.type)) {\n                  if (that.require('factory').isModel(propVal.type)) {\n\n                    links += `\\n\\tedge [\n    arrowhead = \"${propVal.kind ? kindToEdgeStyle[propVal.kind] : 'none'}\"\n    headlabel = \"1\"\n    taillabel = \"\"\n    label     = \"${propVal.description ? propVal.description : ''}\"\n    style     = \"${propVal.kind === 'dependency' ? 'dashed' : 'normal'}\"\n  ]`\n                    links += '\\n\\t' + modelName + ' -> ' + propVal.type + '\\n';\n\n                    if (modelId !== '123751cb591de26' && propVal.type !== '_Component') {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type + '\\\\l';\n                    } else {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type + '\\\\l';\n                    }\n                  } else {\n                    if (['any', 'boolean', 'string', 'number', 'object', 'function', 'array', 'html', 'javascript', 'css', 'json', 'text', 'date'].indexOf(propVal.type) === -1) {\n                      if (modelId !== '123751cb591de26') {\n                        attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type + '\\\\l';\n                        dependencies += '\\n\\t' + modelName + ' -> ' + propVal.type;\n                      } else {\n                        attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type + '\\\\l';\n                        //links += '\\n\\t' + modelName + ' -> ' + propVal.type;\n                      }\n                    } else {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type + '\\\\l';\n                    }\n                  }\n                } else {\n                  if (that.require('factory').isModel(propVal.type[0])) {\n\n                    collections += `\\n\\tedge [\n    arrowhead = \"${propVal.kind ? kindToEdgeStyle[propVal.kind] : 'none'}\"\n    headlabel = \"0..*\"\n    taillabel = \"\"\n    label     = \"${propVal.description ? propVal.description : ''}\"\n    style     = \"${propVal.kind === 'dependency' ? 'dashed' : 'normal'}\"\n  ]`;\n\n                    collections += '\\n\\t' + modelName + ' -> ' + propVal.type[0] + '\\n';\n\n                    if (modelId !== '123751cb591de26' && propVal.type[0] !== '_Component') {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type[0] + ' [ ]\\\\l';\n                    } else {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type[0] + ' [ ]\\\\l';\n                    }\n                  } else {\n                    if (['any', 'boolean', 'string', 'number', 'object', 'function', 'array', 'html', 'javascript', 'css', 'json', 'text', 'date'].indexOf(propVal.type[0]) === -1) {\n                      if (modelId !== '123751cb591de26') {\n                        attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type[0] + ' [ ]\\\\l';\n                        //collections += '\\n\\t' + modelName + ' -> ' + propVal.type[0];\n                        dependencies += '\\n\\t' + modelName + ' -> ' + propVal.type[0];\n                      } else {\n                        attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type[0] + ' [ ]\\\\l';\n\n                        collections += `\\n\\tedge [\n    arrowhead = \"${propVal.kind ? kindToEdgeStyle[propVal.kind] : 'none'}\"\n    headlabel = \"0..*\"\n    taillabel = \"\"\n    label     = \"${propVal.description ? propVal.description : ''}\"\n    style     = \"${propVal.kind === 'dependency' ? 'dashed' : 'normal'}\"\n  ]`;\n\n                        collections += '\\n\\t' + modelName + ' -> ' + propVal.type[0] + '\\n';\n                      }\n                    } else {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type[0] + ' [ ]\\\\l';\n                      //collections += '\\n\\t' + modelName + ' -> ' + propVal.type[0];\n                      // do not show types as links\n                    }\n                  }\n                }\n                break;\n\n              case typeof propVal.params !== 'undefined':\n                result = 'undefined';\n                var params = '(';\n                propVal.params.forEach(callbackProp.bind(this));\n                params = params + ')';\n                params = params.replace(', )', ')');\n\n                if (typeof propVal.result !== 'undefined') {\n                  result = _getReturnType(propVal.result);\n                  if (modelId !== '123751cb591de26') {\n                    methods += '\\n\\t\\t\\t+ ' + propName + params + ' : ' + result + '\\\\l';\n                  } else {\n                    methods += '\\n\\t\\t\\t+ ' + propName + params + ' : ' + result + '\\\\l';\n                  }\n                } else {\n                  if (modelId !== '123751cb591de26') {\n                    methods += '\\n\\t\\t\\t+ ' + propName + params + '\\\\l';\n                  } else {\n                    methods += '\\n\\t\\t\\t+ ' + propName + params + '\\\\l';\n                  }\n                }\n                break;\n\n              case propName.indexOf('_') !== -1:\n                // we do not show private / internal properties\n                break;\n\n              default:\n                result = 'undefined';\n                if (typeof propVal.result !== 'undefined') {\n                  result = _getReturnType(propVal.result);\n\n                  if (modelId !== '123751cb591de26') {\n                    methods += '\\n\\t\\t\\t+ ' + propName + '() : ' + result + '\\\\l';\n                  } else {\n                    methods += '\\n\\t\\t\\t+ ' + propName + '() : ' + result + '\\\\l';\n                  }\n                } else {\n                  if (modelId !== '123751cb591de26') {\n                    methods += '\\n\\t\\t\\t+ ' + propName + '()\\\\l';\n                  } else {\n                    methods += '\\n\\t\\t\\t+ ' + propName + '()\\\\l';\n                  }\n                }\n                break;\n            }\n          }\n        }\n\n        modelDescription += _clean(attributes) + '|' + _clean(methods);\n        modelDescription += '\\n\\t\\t}\"\\r\\t]';\n      }\n\n      // create inheritance links\n      for (var schema in schemas) {\n        if (schemas[schema]._inherit && schemas[schema]._inherit.length) {\n          schemas[schema]._inherit.forEach(function (parent) {\n            inheritance += '\\n\\t' + schemas[schema]._name + ' -> ' + parent;\n          });\n        }\n      }\n\n      // case of Component\n      if (inheritance.indexOf('_Component') !== -1) {\n        modelDescription += `\\n\\n\\t_Component [\n      label = \"{\\n\\t\\t\\t_Component|\\n\\t\\t\\t+ id : string\\\\l|\\n\\t\\t\\t+ classInfo() : _ClassInfo\\\\l\\n\\t\\t\\t+ destroy()\\\\l\\n\\t\\t\\t+ error(data : errorParam)\\\\l\\n\\t\\t\\t+ init(conf : object)\\\\l\\n\\t\\t\\t+ off(state : string, behaviorId : string)\\\\l\\n\\t\\t\\t+ on(state : string, action : function, useCoreAPI : boolean, isCore : boolean) : string\\\\l\\n\\t\\t\\t+ require(id : string) : _Component\\\\l\\n\\t\\t}\"\n  ]`\n      };\n      break;\n\n    default:\n      break;\n  }\n\n  // DIAGRAM\n \n  switch (diagramType) {\n    case 'graph':\n      generatedDiagram = `digraph system {\n  fontname = \"Bitstream Vera Sans\"\n  rankdir = LR\n  size = 8\n\n  node [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n    shape = \"circle\"\n  ]\n  ${modelDescription}\n  ${edges}\n}`;\n      break;\n\n    case 'component':\n      generatedDiagram = `digraph system {\n  fontname = \"Bitstream Vera Sans\"\n  fontsize = 10\n      \n  node [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n    shape = \"record\"\n  ]\n  ${instances}\n  \n  node [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n    shape = \"record\"\n    style = \"rounded\"\n  ]\n  ${instancesRelation}\n  \n  edge [\n    arrowhead = \"none\"\n    headlabel = \"\"\n    taillabel = \"\"\n    label     = \"\"\n    style     = \"normal\"\n  ]\n  ${dependencies}\n  \n  edge [\n    arrowhead = \"vee\"\n    headlabel = \"\"\n    taillabel = \"\"\n    label     = \"\"\n    style     = \"normal\"\n  ]\n  ${relationships}\n}`;\n      break;\n\n    case 'class':\n      generatedDiagram = `digraph system {\n  fontname = \"Bitstream Vera Sans\"\n  fontsize = 10\n\n  node [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n    shape = \"record\"\n  ]\n  \n  edge [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n  ]${modelDescription}\n  \n  node [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n  ]\n  ${instances}\n  \n  edge [\n    arrowhead = \"vee\"\n    headlabel = \"\"\n    taillabel = \"\"\n    label     = \"\"\n    style     = \"dashed\"\n  ]\n  ${dependencies}\n  \n  edge [\n    arrowhead = \"vee\"\n    headlabel = \"\"\n    taillabel = \"\"\n    label     = \"\"\n    style     = \"dashed\"\n  ]\n  ${instancesOf}\n  \n  ${links}\n  ${collections}\n  edge [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n    arrowhead = \"empty\"\n    headlabel = \"\"\n    taillabel = \"\"\n    label     = \"\"\n    style     = \"normal\"\n  ]\n  ${inheritance}\n}`;\n      break;\n\n    default:\n      break;\n  }\n\n  return generatedDiagram;\n}",
      "useCoreAPI": false,
      "core": false
    }
  },
  "types": {},
  "components": { "Export": { "export": { "_id": "export" } } },
  "_id": "b1b4c41801f15706"
}<commit_msg>fix issues with internal graphviz keywords<commit_after>{
  "name": "Export-class",
  "master": false,
  "version": "0.0.1",
  "description": "",
  "schemas": {
    "v1dfff1f04618899": {
      "_id": "v1dfff1f04618899",
      "_name": "Export",
      "_inherit": ["_Component"],
      "toJSON": "method",
      "toHTML": "method",
      "toJavaScript": "method",
      "toNode": "method",
      "toGraphviz": "method"
    }
  },
  "models": {
    "v1ca291072418fa4": {
      "_id": "v1ca291072418fa4",
      "_name": "Export",
      "toJSON": {
        "params": [
          {
            "name": "isMaster",
            "type": "boolean",
            "mandatory": false,
            "default": true
          }
        ],
        "result": "string"
      },
      "toHTML": {
        "params": [
          {
            "name": "logLevel",
            "type": "string",
            "mandatory": false,
            "default": "info"
          }
        ],
        "result": "string"
      },
      "toNode": {
        "params": [
          {
            "name": "logLevel",
            "type": "string",
            "mandatory": false,
            "default": "info"
          }
        ],
        "result": "string"
      },
      "toJavaScript": {
        "params": [
          {
            "name": "logLevel",
            "type": "string",
            "mandatory": false,
            "default": "info"
          }
        ],
        "result": "string"
      },
      "toGraphviz": {
        "description": "",
        "params": [
          {
            "name": "diagramType",
            "description": "",
            "type": "string",
            "mandatory": false,
            "default": "class"
          }
        ],
        "result": "string"
      }
    }
  },
  "behaviors": {
    "p14b27128f61643e": {
      "_id": "p14b27128f61643e",
      "component": "Export",
      "state": "toJSON",
      "action": "function toJSON(isMaster) {\n  var system = this.require('db').collections().System.find({\n    '_id': this.require('factory').system().id()\n  })[0];\n  system = JSON.parse(JSON.stringify(system));\n  delete system.classInfo;\n\n  system = JSON.parse(JSON.stringify(system));\n\n  if (isMaster) {\n    system.master = true;\n  } else {\n    system.master = false;\n  }\n\n  return JSON.stringify(system);\n}",
      "useCoreAPI": false,
      "core": false
    },
    "g131c91154e14849": {
      "_id": "g131c91154e14849",
      "component": "Export",
      "state": "toHTML",
      "action": "function toHTML(logLevel) {\n  var system = this.require('db').collections().System.find({\n    '_id': this.require('factory').system().id()\n  })[0];\n  system = JSON.parse(JSON.stringify(system));\n  delete system.classInfo;\n\n  var source = this.require('export-app.html').source();\n\n  source = source\n    .replace(/{{name}}/g, this.require('factory').system().name())\n    .replace(/{{logLevel}}/g, $('#designer-dialog-export-options-log-level-select').val())\n    .replace(/{{system}}/g, function (val) { return JSON.stringify(system) });\n\n  return source;\n}",
      "useCoreAPI": false,
      "core": false
    },
    "r11d81144f810201": {
      "_id": "r11d81144f810201",
      "component": "Export",
      "state": "toNode",
      "action": "function toNode(logLevel) {\n  var system = this.require('db').collections().System.find({\n    '_id': this.require('factory').system().id()\n  })[0];\n  system = JSON.parse(JSON.stringify(system));\n  delete system.classInfo;\n\n  var source = this.require('app.js').source();\n\n  source = source\n    .replace(/{{version}}/g, this.require('factory').system().version())\n    .replace(/{{description}}/g, this.require('factory').system().description().replace(/\\n/g, '\\n * '))\n    .replace(/{{name}}/g, this.require('factory').system().name())\n    .replace(/{{logLevel}}/g, $('#designer-dialog-export-options-log-level-select').val())\n    .replace(/{{system}}/g, JSON.stringify(system));\n\n  return source;\n}",
      "useCoreAPI": false,
      "core": false
    },
    "h14919197fb17aaf": {
      "_id": "h14919197fb17aaf",
      "component": "Export",
      "state": "toJavaScript",
      "action": "function toJavaScript(logLevel) {\n  var system = this.require('db').collections().System.find({\n    '_id': this.require('factory').system().id()\n  })[0];\n  system = JSON.parse(JSON.stringify(system));\n  delete system.classInfo;\n\n  var source = this.require('javascript-export.js').source();\n\n  source = source\n    .replace(/{{version}}/g, this.require('factory').system().version())\n    .replace(/{{description}}/g, this.require('factory').system().description().replace(/\\n/g, '\\n * '))\n    .replace(/{{name}}/g, this.require('factory').system().name())\n    .replace(/{{logLevel}}/g, $('#designer-dialog-export-options-log-level-select').val());\n\n  // SYSTEM\n\n  var confSystem = {};\n\n  confSystem._id = system._id;\n  confSystem.name = system.name;\n  confSystem.version = system.version;\n  confSystem.description = system.description;\n\n  source = source + '/**\\n';\n  source = source + ' * System ' + confSystem.name + '\\n';\n  source = source + ' * @system\\n';\n  source = source + ' */\\n';\n  source = source + 'runtime.system(' + JSON.stringify(confSystem, null, '\\t', 2) + ');\\n\\n';\n\n  // SCHEMA / MODEL / TYPE     \n  if (Object.keys(system.schemas).length > 0 || Object.keys(system.types).length > 0) {\n    source = source + '\\n// Schemas, models and types creation\\n\\n\\n';\n  }\n\n  var name = '';\n  var schemaSorted = [];\n  var schemaNameSorted = [];\n  var schemaName = {};\n\n  for (name in system.schemas) {\n    schemaSorted.push(system.schemas[name]);\n    schemaNameSorted.push(system.schemas[name]._name);\n    schemaName[system.schemas[name]._name] = system.schemas[name]._name;\n  }\n  schemaSorted.sort(function (schemaA, schemaB) {\n    return schemaA._name > schemaB._name;\n  });\n  schemaNameSorted.sort();\n\n  schemaSorted.forEach(function (schema) {\n    source = source + '/**\\n';\n    source = source + ' * Schema ' + schema._name + '\\n';\n    source = source + ' * @schema\\n';\n    source = source + ' */\\n';\n    source = source + 'runtime.require(\\'metamodel\\').schema(' + JSON.stringify(schema, null, '\\t', 2) + ');\\n\\n';\n  });\n\n  var modelSorted = [];\n  var modelNameSorted = [];\n  for (name in system.models) {\n    modelSorted.push(system.models[name]);\n    modelNameSorted.push(system.models[name]._name);\n  }\n  modelSorted.sort(function (modelA, modelB) {\n    return modelA._name > modelB._name;\n  });\n  modelNameSorted.sort();\n\n  modelSorted.forEach(function (model) {\n    source = source + '/**\\n';\n    source = source + ' * Model ' + model._name + '\\n';\n    source = source + ' * @model\\n';\n    source = source + ' */\\n';\n    source = source + 'runtime.require(\\'metamodel\\').model(' + JSON.stringify(model, null, '\\t', 2) + ');\\n\\n';\n  });\n\n  var typeSorted = [];\n  var typeNameSorted = [];\n  for (name in system.types) {\n    typeSorted.push(system.types[name]);\n    typeNameSorted.push(system.types[name].name);\n  }\n  typeSorted.sort(function (typeA, typeB) {\n    return typeA.name > typeB.name;\n  });\n  typeNameSorted.sort();\n\n  typeSorted.forEach(function (type) {\n    source = source + '/**\\n';\n    source = source + ' * Type ' + type.name + '\\n';\n    source = source + ' * @type\\n';\n    source = source + ' */\\n';\n    source = source + 'runtime.require(\\'metamodel\\').type(' + JSON.stringify(type, null, '\\t', 2) + ');\\n\\n';\n  });\n\n  if (Object.keys(system.schemas).length > 0 || Object.keys(system.models).length > 0 || Object.keys(system.types).length > 0) {\n    source = source + 'runtime.require(\\'metamodel\\').create();\\n\\n';\n  }\n\n  // COMPONENT   \n  if (Object.keys(system.components).length > 0) {\n    source = source + '\\n// Components creation\\n\\n\\n';\n  }\n  schemaNameSorted.forEach(function (collection) {\n    for (name in system.components[collection]) {\n      source = source + '/**\\n';\n      source = source + ' * Component ' + system.components[collection][name]._id + '\\n';\n      source = source + ' * @component\\n';\n      source = source + ' */\\n';\n      source = source + 'new (runtime.require(\\'' + collection + '\\'))(' + JSON.stringify(system.components[collection][name], null, '\\t', 2) + ');\\n\\n';\n    }\n  });\n\n  // BEHAVIOR   \n  if (Object.keys(system.behaviors).length > 0) {\n    source = source + '\\n// Behaviors creation\\n\\n\\n';\n  }\n\n  var behaviors = {};\n  var behaviorsComponentNameSorted = [];\n  var modelsByName = {};\n\n  for (name in system.behaviors) {\n    if (typeof behaviors[system.behaviors[name].component] === 'undefined') {\n      behaviors[system.behaviors[name].component] = [];\n    }\n    behaviors[system.behaviors[name].component].push(system.behaviors[name]);\n  }\n\n  behaviorsComponentNameSorted = Object.keys(behaviors);\n  behaviorsComponentNameSorted.sort();\n\n  var id = '';\n  for (id in system.models) {\n    modelsByName[system.models[id]._name] = system.models[id];\n  }\n\n  behaviorsComponentNameSorted.forEach(function forEach(componentName) {\n    var componentBehaviors = behaviors[componentName];\n\n    componentBehaviors.sort(function sort(behaviorA, behaviorB) {\n      return behaviorA.state > behaviorB.state;\n    });\n\n    if (componentBehaviors.length > 0) {\n      if (componentName === system._id) {\n        source = source + '// system behaviors\\n\\n';\n      } else {\n        source = source + '// ' + componentName + ' behaviors\\n\\n';\n      }\n    }\n\n    componentBehaviors.forEach(function forEach(behavior) {\n      var useCoreAPI = typeof behavior.useCoreAPI !== 'undefined' ? behavior.useCoreAPI : false;\n      var core = typeof behavior.core !== 'undefined' ? behavior.core : false;\n      var comp = '';\n      var behaviorParamDef = {};\n      var options = ');\\n\\n';\n\n      if (useCoreAPI && !core) {\n        options = ', true);\\n\\n';\n      }\n      if (useCoreAPI && core) {\n        options = ', true, true);\\n\\n';\n      }\n\n      source = source + '/**\\n';\n      source = source + ' * @method ' + behavior.state + '\\n';\n\n      if (modelsByName[behavior.component] && modelsByName[behavior.component][behavior.state] && modelsByName[behavior.component][behavior.state].params) {\n        modelsByName[behavior.component][behavior.state].params.forEach(function forEach(param) {\n          source = source + ' * @param {' + param.type + '} ' + param.name + '\\n';\n        });\n      }\n      if (modelsByName[behavior.component] && modelsByName[behavior.component][behavior.state] && modelsByName[behavior.component][behavior.state].result) {\n        source = source + ' * @returns {' + modelsByName[behavior.component][behavior.state].result + '} \\n';\n      }\n\n      source = source + ' */\\n';\n\n      switch (true) {\n        case behavior.component === system._id:\n          comp = 'runtime.system()';\n          break;\n        default:\n          comp = 'runtime.require(\\'' + behavior.component + '\\')';\n          break;\n      }\n\n      source = source + comp + '.on(\\'' + behavior.state + '\\', ' + behavior.action + options;\n    })\n  });\n\n  // START\n  source = source + '// Start the system\\n';\n  source = source + 'runtime.system().start();\\n';\n\n  return source;\n}",
      "useCoreAPI": false,
      "core": false
    },
    "e13c7916b1a15fc4": {
      "_id": "e13c7916b1a15fc4",
      "component": "Export",
      "state": "toGraphviz",
      "action": "function toGraphviz(diagramType) {\n  var schemas = this.require('factory').system().schemas();\n  var models = this.require('factory').system().models();\n  var types = this.require('factory').system().types();\n  var components = this.require('factory').system().components();\n  var inheritance = '';\n  var modelId = '';\n  var typeId = '';\n  var componentId = '';\n  var modelName = '';\n  var typeName = '';\n  var modelDescription = '';\n  var propName = '';\n  var propVal = '';\n  var propDef = '';\n  var attributes = '';\n  var methods = '';\n  var result = '';\n  var dependencies = '';\n  var instancesOf = '';\n  var links = '';\n  var collections = '';\n  var instances = '';\n  var that = this;\n  var keys = [];\n  var sortedKeys = {};\n  var generatedDiagram = '';\n  var parents = '';\n  var modelNames = [];\n  var modelDef = {};\n  var schemaDef = {};\n  var incoming = '';\n  var outgoing = '';\n  var edges = '';\n  var relationships = '';\n  var instancesRelation ='';\n  var kindToEdgeStyle = {\n    'normal': 'none',\n    'dependency': 'vee',\n    'composition': 'diamond',\n    'aggregation': 'odiamond'\n  };\n\n  callbackProp = function (param) {\n    var realType = param.type;\n    var isArray = false;\n\n    if (Array.isArray(param.type)) {\n      isArray = true;\n      realType = param.type[0];\n    }\n\n    if (that.require('factory').isModel(realType) && realType !== '_Component') {\n      if (isArray) {\n        params = params + param.name + ' : [' + realType + '], ';\n      } else {\n        params = params + param.name + ' : ' + realType + ', ';\n      }\n    } else {\n      if (['any', 'boolean', 'string', 'number', 'object', 'function', 'array', 'html', 'javascript', 'css', 'errorParam', 'json', 'text', 'date'].indexOf(realType) === -1 && realType !== '_Component') {\n        if (isArray) {\n          params = params + param.name + ' : [' + realType + '], ';\n        } else {\n          params = params + param.name + ' : ' + realType + ', ';\n        }\n      } else {\n        if (isArray) {\n          params = params + param.name + ' : [' + realType + '], ';\n        } else {\n          params = params + param.name + ' : ' + realType + ', ';\n        }\n      }\n    }\n  };\n\n  function _getReturnType(returnType) {\n    var result = '';\n    var realType = returnType;\n    var isArray = false;\n\n    if (Array.isArray(returnType)) {\n      isArray = true;\n      realType = returnType[0];\n    }\n\n    if (that.require('factory').isModel(realType) && realType !== '_Component' && realType !== '_ClassInfo') {\n      if (isArray) {\n        result = '[' + realType + ']';\n      } else {\n        result = realType;\n      }\n    } else {\n      if (['any', 'boolean', 'string', 'number', 'object', 'function', 'array', 'html', 'javascript', 'css', 'errorParam', 'json', 'text', 'date'].indexOf(realType) === -1 && realType !== '_Component' && realType !== '_ClassInfo') {\n        if (isArray) {\n          result = '[' + realType + ']';\n        } else {\n          result = realType;\n        }\n      } else {\n        if (isArray) {\n          result = '[' + realType + ']';\n        } else {\n          result = realType;\n        }\n      }\n    }\n    return result;\n  }\n\n  function _getModelId(name) {\n    var result = '',\n      id = '';\n\n    for (id in that.require('factory').system().models()) {\n      if (that.require('factory').system().models()[id]._name === name) {\n        result = id;\n        break;\n      }\n    }\n    return result;\n  }\n\n  function _isType(name) {\n    return typeof types[name] !== 'undefined';\n  }\n\n  function _clean(text) {\n    return text.replace(/\\{/g, '').replace(/\\}/g, '');\n  }\n\n  function _cleanName(text) {\n    return text.toString()\n              .replace(/\\./g, '')\n              .replace(/\\-/g, '')\n              .replace(/node/i, '_node')\n              .replace(/edge/i, '_edge')\n              .replace(/graph/i, '_graph')\n              .replace(/digraph/i, '_digraph')\n              .replace(/subgraph/i, '_subgraph')\n              .replace(/strict/i, '_strict');\n  }\n\n  function _cleanVal(text) {\n    var clean = JSON.stringify(text).replace(/\\\"/g, '\\'')\n      .replace(/\\./g, '\\\\.')\n      .replace(/\\-/g, '\\\\-')\n      .replace(/\\{/g, '\\\\{')\n      .replace(/\\}/g, '\\\\}')\n      .replace(/\\</g, '\\\\<')\n      .replace(/\\>/g, '\\\\>')\n      .replace(/\\\\n/g, '');\n\n    if (clean.length > 42) {\n      return clean.substring(0, 42) + '...';\n    } else {\n      return clean;\n    }\n  }\n\n  // COMPUTATION\n\n  switch (diagramType) {\n    case 'graph':\n\n      // create node\n      for (modelId in models) {\n\n        modelName = models[modelId]._name;\n        parents = this.require('factory').getParents(modelName);\n        if (modelName !== 'Nodes' && modelName !== 'Relationships' && parents.indexOf('Nodes') !== -1) {\n          modelNames.push(modelName);\n          modelDescription += '\\n\\n\\t' + _cleanName(modelName) + ' [\\n\\t\\tlabel = ' + modelName + '\\n\\t]';\n        }\n      }\n\n      // create relationships\n      for (modelId in models) {\n\n        modelName = models[modelId]._name;\n        parents = this.require('factory').getParents(modelName);\n        modelDef = this.require('factory').getGeneratedModel(modelName);\n        if (modelName !== 'Nodes' && modelName !== 'Relationships' && parents.indexOf('Relationships') !== -1) {\n          incoming = modelDef.incoming.type;\n          outgoing = modelDef.outgoing.type;\n\n          edges += `\\n\\tedge [\n    headlabel = \"\"\n    taillabel = \"\"\n    fontsize = 5\n    label     = ${modelName}\n  ]`;\n\n          switch (true) {\n            case incoming === 'Nodes' && outgoing === 'Nodes':\n              modelNames.forEach(function (incoming) {\n                modelNames.forEach(function (outgoing) {\n                  edges += '\\n\\t' + _cleanName(incoming) + ' -> ' + _cleanName(outgoing) + '\\n';\n                });\n              });\n              break;\n            case incoming === 'Nodes' && outgoing !== 'Nodes':\n              modelNames.forEach(function (incoming) {\n                edges += '\\n\\t' + _cleanName(incoming) + ' -> ' + _cleanName(outgoing) + '\\n';\n              });\n              break;\n            case incoming !== 'Nodes' && outgoing !== 'Nodes':\n              edges += '\\n\\t' + _cleanName(incoming) + ' -> ' + _cleanName(outgoing) + '\\n';\n              break;\n            default:\n              break;\n          }\n        }\n      }\n\n      break;\n\n    case 'component':\n\n      // create instances\n      for (modelName in components) {\n        schemaDef = this.require('factory').getGeneratedSchema(modelName);\n        parents = this.require('factory').getParents(modelName);\n\n        for (componentId in components[modelName]) {\n          \n          if (modelName === 'Relationships' || parents.indexOf('Relationships') !== -1) {\n            instancesRelation += '\\n\\n\\t' + _cleanName(componentId) + ' [\\n\\t\\tlabel = \"{\\n\\t\\t\\t' + componentId + ' : ' + modelName + '|';\n          } else {\n            instances += '\\n\\n\\t' + _cleanName(componentId) + ' [\\n\\t\\tlabel = \"{\\n\\t\\t\\t' + componentId + ' : ' + modelName + '|';\n          }\n          attributes = '';\n          \n          keys = [];\n          sortedKeys = {};\n          \n           // get keys\n          for (propName in components[modelName][componentId]) {\n            keys.push(propName);\n          }\n          keys.sort();\n          \n          // sorted keys\n          keys.forEach(function(key) {\n            sortedKeys[key] = components[modelName][componentId][key];\n          }.bind(this));\n\n          for (var prop in sortedKeys) {\n            if (prop !== '_id') {\n              if (prop !== 'incoming' && prop !== 'outgoing') {\n                if (schemaDef[prop] && schemaDef[prop] === 'collection') {\n                  if (sortedKeys[prop].length > 0) {\n                    attributes += '\\n\\t\\t\\t' + prop + ' = [\\\\l' + sortedKeys[prop].map(function(item) { return _cleanVal(item)}).join(',\\\\l') + '\\\\l]\\\\l'; \n                  } else {\n                    attributes += '\\n\\t\\t\\t' + prop + ' = []\\\\l'; \n                  }\n                } else {\n                  attributes += '\\n\\t\\t\\t' + prop + ' = ' + _cleanVal(sortedKeys[prop]) + '\\\\l';\n                }\n              }\n              \n              if (schemaDef[prop] && (schemaDef[prop] === 'link' || schemaDef[prop] === 'collection')) {\n                if (sortedKeys[prop] !== '') {\n                \n                  switch(prop) {\n                    case 'incoming':\n                      relationships += '\\n\\t' + _cleanName(sortedKeys[prop]) + ' -> ' + _cleanName(componentId); \n                      break;\n                    case 'outgoing':\n                      relationships += '\\n\\t' + _cleanName(componentId) + ' -> ' + _cleanName(sortedKeys[prop]); \n                      break;\n                    default:\n                      if (Array.isArray(sortedKeys[prop])) {\n                        sortedKeys[prop].forEach(function(item) {\n                          dependencies += '\\n\\t' + _cleanName(componentId) + ' -> ' + _cleanName(item);  \n                        })\n                      } else {\n                        dependencies += '\\n\\t' + _cleanName(componentId) + ' -> ' + _cleanName(sortedKeys[prop]);\n                      }\n                      break;\n                  }\n                }\n              }\n            }\n          }\n\n          if (modelName === 'Relationships' || parents.indexOf('Relationships') !== -1) {\n            instancesRelation += attributes;\n            instancesRelation += '\\n\\t\\t}\"\\r\\t]';\n          } else {\n            instances += attributes;\n            instances += '\\n\\t\\t}\"\\r\\t]';\n          }\n        }\n      }\n      break;\n\n    case 'class':\n\n      // create model for types\n      for (typeId in types) {\n\n        // structure\n        if (types[typeId].schema) {\n          typeName = types[typeId].name;\n          modelDescription += '\\n\\n\\t' + _cleanName(typeName) + ' [\\n\\t\\tlabel = \"{\\n\\t\\t\\t' + typeName + '|';\n\n          attributes = '';\n          keys = [];\n          sortedKeys = {};\n\n          // get keys\n          for (propName in types[typeId].schema) {\n            keys.push(propName);\n          }\n          keys.sort();\n\n          // sorted keys\n          keys.forEach(function (key) {\n            sortedKeys[key] = types[typeId].schema[key];\n          }.bind(this));\n\n          for (propName in sortedKeys) {\n            if (types[typeId].schema.hasOwnProperty(propName)) {\n              propDef = types[typeId].schema[propName];\n              attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propDef.type + '\\\\l';\n              if (_isType(propDef.type)) {\n                dependencies += '\\n\\t' + _cleanName(typeName) + ' -> ' + propDef.type;\n              }\n            }\n          }\n\n          modelDescription += _clean(attributes);\n          modelDescription += '\\n\\t\\t}\"\\r\\t]';\n        }\n\n        // enumeration\n        if (types[typeId].value) {\n          typeName = types[typeId].name;\n          modelDescription += '\\n\\n\\t' + _cleanName(typeName) + ' [\\n\\t\\tlabel = \"{\\n\\t\\t\\t\\\\<\\\\<enumeration\\\\>\\\\>\\\\l' + typeName + '|';\n\n          attributes = '';\n\n          types[typeId].value.forEach(function (enumValue) {\n            attributes += '\\n\\t\\t\\t' + enumValue + '\\\\l';\n          });\n\n          modelDescription += _clean(attributes);\n          modelDescription += '\\n\\t\\t}\"\\r\\t]';\n        }\n      }\n\n      // create model\n      for (modelId in models) {\n\n        modelName = models[modelId]._name;\n        modelDescription += '\\n\\n\\t' + _cleanName(modelName) + ' [\\n\\t\\tlabel = \"{\\n\\t\\t\\t' + modelName + '|';\n\n        attributes = '';\n        methods = '';\n        keys = [];\n        sortedKeys = {};\n\n        // get keys\n        for (propName in models[modelId]) {\n          keys.push(propName);\n        }\n        keys.sort();\n\n        // sorted keys\n        keys.forEach(function (key) {\n          sortedKeys[key] = models[modelId][key];\n        }.bind(this));\n\n        for (propName in sortedKeys) {\n          if (models[modelId].hasOwnProperty(propName)) {\n            propVal = models[modelId][propName];\n\n            switch (true) {\n              case typeof propVal.type !== 'undefined':\n                if (!Array.isArray(propVal.type)) {\n                  if (that.require('factory').isModel(propVal.type)) {\n\n                    links += `\\n\\tedge [\n    arrowhead = \"${propVal.kind ? kindToEdgeStyle[propVal.kind] : 'none'}\"\n    headlabel = \"1\"\n    taillabel = \"\"\n    label     = \"${propVal.description ? propVal.description : ''}\"\n    style     = \"${propVal.kind === 'dependency' ? 'dashed' : 'normal'}\"\n  ]`\n                    links += '\\n\\t' + _cleanName(modelName) + ' -> ' + propVal.type + '\\n';\n\n                    if (modelId !== '123751cb591de26' && propVal.type !== '_Component') {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type + '\\\\l';\n                    } else {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type + '\\\\l';\n                    }\n                  } else {\n                    if (['any', 'boolean', 'string', 'number', 'object', 'function', 'array', 'html', 'javascript', 'css', 'json', 'text', 'date'].indexOf(propVal.type) === -1) {\n                      if (modelId !== '123751cb591de26') {\n                        attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type + '\\\\l';\n                        dependencies += '\\n\\t' + _cleanName(modelName) + ' -> ' + propVal.type;\n                      } else {\n                        attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type + '\\\\l';\n                        //links += '\\n\\t' + modelName + ' -> ' + propVal.type;\n                      }\n                    } else {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type + '\\\\l';\n                    }\n                  }\n                } else {\n                  if (that.require('factory').isModel(propVal.type[0])) {\n\n                    collections += `\\n\\tedge [\n    arrowhead = \"${propVal.kind ? kindToEdgeStyle[propVal.kind] : 'none'}\"\n    headlabel = \"0..*\"\n    taillabel = \"\"\n    label     = \"${propVal.description ? propVal.description : ''}\"\n    style     = \"${propVal.kind === 'dependency' ? 'dashed' : 'normal'}\"\n  ]`;\n\n                    collections += '\\n\\t' + _cleanName(modelName) + ' -> ' + propVal.type[0] + '\\n';\n\n                    if (modelId !== '123751cb591de26' && propVal.type[0] !== '_Component') {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type[0] + ' [ ]\\\\l';\n                    } else {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type[0] + ' [ ]\\\\l';\n                    }\n                  } else {\n                    if (['any', 'boolean', 'string', 'number', 'object', 'function', 'array', 'html', 'javascript', 'css', 'json', 'text', 'date'].indexOf(propVal.type[0]) === -1) {\n                      if (modelId !== '123751cb591de26') {\n                        attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type[0] + ' [ ]\\\\l';\n                        //collections += '\\n\\t' + modelName + ' -> ' + propVal.type[0];\n                        dependencies += '\\n\\t' + _cleanName(modelName) + ' -> ' + propVal.type[0];\n                      } else {\n                        attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type[0] + ' [ ]\\\\l';\n\n                        collections += `\\n\\tedge [\n    arrowhead = \"${propVal.kind ? kindToEdgeStyle[propVal.kind] : 'none'}\"\n    headlabel = \"0..*\"\n    taillabel = \"\"\n    label     = \"${propVal.description ? propVal.description : ''}\"\n    style     = \"${propVal.kind === 'dependency' ? 'dashed' : 'normal'}\"\n  ]`;\n\n                        collections += '\\n\\t' + _cleanName(modelName) + ' -> ' + propVal.type[0] + '\\n';\n                      }\n                    } else {\n                      attributes += '\\n\\t\\t\\t+ ' + propName + ' : ' + propVal.type[0] + ' [ ]\\\\l';\n                      //collections += '\\n\\t' + modelName + ' -> ' + propVal.type[0];\n                      // do not show types as links\n                    }\n                  }\n                }\n                break;\n\n              case typeof propVal.params !== 'undefined':\n                result = 'undefined';\n                var params = '(';\n                propVal.params.forEach(callbackProp.bind(this));\n                params = params + ')';\n                params = params.replace(', )', ')');\n\n                if (typeof propVal.result !== 'undefined') {\n                  result = _getReturnType(propVal.result);\n                  if (modelId !== '123751cb591de26') {\n                    methods += '\\n\\t\\t\\t+ ' + propName + params + ' : ' + result + '\\\\l';\n                  } else {\n                    methods += '\\n\\t\\t\\t+ ' + propName + params + ' : ' + result + '\\\\l';\n                  }\n                } else {\n                  if (modelId !== '123751cb591de26') {\n                    methods += '\\n\\t\\t\\t+ ' + propName + params + '\\\\l';\n                  } else {\n                    methods += '\\n\\t\\t\\t+ ' + propName + params + '\\\\l';\n                  }\n                }\n                break;\n\n              case propName.indexOf('_') !== -1:\n                // we do not show private / internal properties\n                break;\n\n              default:\n                result = 'undefined';\n                if (typeof propVal.result !== 'undefined') {\n                  result = _getReturnType(propVal.result);\n\n                  if (modelId !== '123751cb591de26') {\n                    methods += '\\n\\t\\t\\t+ ' + propName + '() : ' + result + '\\\\l';\n                  } else {\n                    methods += '\\n\\t\\t\\t+ ' + propName + '() : ' + result + '\\\\l';\n                  }\n                } else {\n                  if (modelId !== '123751cb591de26') {\n                    methods += '\\n\\t\\t\\t+ ' + propName + '()\\\\l';\n                  } else {\n                    methods += '\\n\\t\\t\\t+ ' + propName + '()\\\\l';\n                  }\n                }\n                break;\n            }\n          }\n        }\n\n        modelDescription += _clean(attributes) + '|' + _clean(methods);\n        modelDescription += '\\n\\t\\t}\"\\r\\t]';\n      }\n\n      // create inheritance links\n      for (var schema in schemas) {\n        if (schemas[schema]._inherit && schemas[schema]._inherit.length) {\n          schemas[schema]._inherit.forEach(function (parent) {\n            inheritance += '\\n\\t' + _cleanName(schemas[schema]._name) + ' -> ' + parent;\n          });\n        }\n      }\n\n      // case of Component\n      if (inheritance.indexOf('_Component') !== -1) {\n        modelDescription += `\\n\\n\\t_Component [\n      label = \"{\\n\\t\\t\\t_Component|\\n\\t\\t\\t+ id : string\\\\l|\\n\\t\\t\\t+ classInfo() : _ClassInfo\\\\l\\n\\t\\t\\t+ destroy()\\\\l\\n\\t\\t\\t+ error(data : errorParam)\\\\l\\n\\t\\t\\t+ init(conf : object)\\\\l\\n\\t\\t\\t+ off(state : string, behaviorId : string)\\\\l\\n\\t\\t\\t+ on(state : string, action : function, useCoreAPI : boolean, isCore : boolean) : string\\\\l\\n\\t\\t\\t+ require(id : string) : _Component\\\\l\\n\\t\\t}\"\n  ]`\n      };\n      break;\n\n    default:\n      break;\n  }\n\n  // DIAGRAM\n \n  switch (diagramType) {\n    case 'graph':\n      generatedDiagram = `digraph system {\n  fontname = \"Bitstream Vera Sans\"\n  rankdir = LR\n  size = 8\n\n  node [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n    shape = \"circle\"\n  ]\n  ${modelDescription}\n  ${edges}\n}`;\n      break;\n\n    case 'component':\n      generatedDiagram = `digraph system {\n  fontname = \"Bitstream Vera Sans\"\n  fontsize = 10\n      \n  node [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n    shape = \"record\"\n  ]\n  ${instances}\n  \n  node [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n    shape = \"record\"\n    style = \"rounded\"\n  ]\n  ${instancesRelation}\n  \n  edge [\n    arrowhead = \"none\"\n    headlabel = \"\"\n    taillabel = \"\"\n    label     = \"\"\n    style     = \"normal\"\n  ]\n  ${dependencies}\n  \n  edge [\n    arrowhead = \"vee\"\n    headlabel = \"\"\n    taillabel = \"\"\n    label     = \"\"\n    style     = \"normal\"\n  ]\n  ${relationships}\n}`;\n      break;\n\n    case 'class':\n      generatedDiagram = `digraph system {\n  fontname = \"Bitstream Vera Sans\"\n  fontsize = 10\n\n  node [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n    shape = \"record\"\n  ]\n  \n  edge [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n  ]${modelDescription}\n  \n  node [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n  ]\n  ${instances}\n  \n  edge [\n    arrowhead = \"vee\"\n    headlabel = \"\"\n    taillabel = \"\"\n    label     = \"\"\n    style     = \"dashed\"\n  ]\n  ${dependencies}\n  \n  edge [\n    arrowhead = \"vee\"\n    headlabel = \"\"\n    taillabel = \"\"\n    label     = \"\"\n    style     = \"dashed\"\n  ]\n  ${instancesOf}\n  \n  ${links}\n  ${collections}\n  edge [\n    fontname = \"Bitstream Vera Sans\"\n    fontsize = 10\n    arrowhead = \"empty\"\n    headlabel = \"\"\n    taillabel = \"\"\n    label     = \"\"\n    style     = \"normal\"\n  ]\n  ${inheritance}\n}`;\n      break;\n\n    default:\n      break;\n  }\n\n  return generatedDiagram;\n}",
      "useCoreAPI": false,
      "core": false
    }
  },
  "types": {},
  "components": { "Export": { "export": { "_id": "export" } } },
  "_id": "b1b4c41801f15706"
}
{'fraction_non_alphanumeric': 0.2171067278151298, 'fraction_numerical': 0.009854995027976906, 'mean_word_length': 1.8160996405583885, 'pattern_counts': {'":': 194, '<': 11, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 82, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6630672', 'n_tokens_mistral': 22178, 'n_tokens_neox': 21284, 'n_words': 4557}