{"name":"mode-admin","master":false,"version":"1.0.0","description":"Enable connection to System Designer","schemas":{"1723516a30132ac":{"_name":"_Database","_inherit":["_Component"],"_core":true,"insert":"event","update":"event","remove":"event","_id":"1723516a30132ac"},"10374180581a41f":{"_id":"10374180581a41f","_name":"_Admin","_inherit":["_Component"],"_core":true,"designerWindow":"property"},"104ad1f48518376":{"_id":"104ad1f48518376","_name":"_Channel","_core":true,"$editorUpdateSystem":"event","$editorUpdateSchema":"event","$editorUpdateSchemaId":"event","$editorUpdateSchemaName":"event","$editorUpdateModel":"event","$editorUpdateModelId":"event","$editorUpdateType":"event","$editorDeleteType":"event","$editorUpdateBehavior":"event","$editorDeleteBehavior":"event","$editorUpdateComponent":"event","$editorUpdateComponentId":"event","$editorDeleteComponent":"event","$appLogDebug":"event","$appLogInfo":"event","$appLogWarn":"event","$appLogError":"event","$appLoadSystem":"event","$designerSync":"event","$designerCreateBehavior":"event","$designerCreateComponent":"event","$designerCreateType":"event","$designerCreateSchema":"event","$designerCreateModel":"event","$designerDeleteSchema":"event","$designerDeleteModel":"event","$designerDeleteType":"event","$designerDeleteBehavior":"event","$designerDeleteComponent":"event","$designerUpdateComponent":"event","$designerUpdateModel":"event","$designerUpdateBehavior":"event","$designerSetSystem":"event","$runtimeCreateComponent":"event","$runtimeDeleteComponent":"event","$runtimeUpdateComponent":"event","send":"event"},"1268f1dddd1fea7":{"_name":"_Logger","_core":true,"level":"property","debug":"method","info":"method","warn":"method","error":"method","_id":"1268f1dddd1fea7"}},"models":{"18a51169d7112d4":{"_name":"_Database","_core":true,"insert":{"params":[{"name":"event","type":"dbInsertEvent"}]},"update":{"params":[{"name":"event","type":"dbUpdateEvent"}]},"remove":{"params":[{"name":"event","type":"dbRemoveEvent"}]},"_id":"18a51169d7112d4"},"138a81fa1f16435":{"_id":"138a81fa1f16435","_name":"_Admin","_inherit":["_Component"],"_core":true,"designerWindow":{"type":"object","readOnly":false,"mandatory":false,"default":null}},"135c71078810af2":{"_id":"135c71078810af2","_name":"_Channel","_inherit":["_Component"],"_core":true,"$editorUpdateSchemaName":{"params":[{"name":"name","type":"string"},{"name":"id","type":"string"}]},"$designerSync":{},"$appLoadSystem":{"params":[{"name":"system","type":"object"}]},"$designerCreateBehavior":{"params":[{"name":"behavior","type":"object"}]},"$editorUpdateBehavior":{"params":[{"name":"id","type":"string"},{"name":"behavior","type":"object"}]},"$designerUpdateBehavior":{"params":[{"name":"id","type":"string"},{"name":"behavior","type":"object"}]},"$editorDeleteBehavior":{"params":[{"name":"id","type":"string"}]},"$designerDeleteBehavior":{"params":[{"name":"id","type":"string"}]},"$designerCreateComponent":{"params":[{"name":"collection","type":"string"},{"name":"component","type":"object"}]},"$editorUpdateComponent":{"params":[{"name":"id","type":"string"},{"name":"collection","type":"string"},{"name":"component","type":"object"}]},"$editorUpdateComponentId":{"params":[{"name":"oldId","type":"string"},{"name":"newId","type":"string"},{"name":"collection","type":"string"}]},"$designerUpdateComponent":{"params":[{"name":"id","type":"string"},{"name":"collection","type":"string"},{"name":"component","type":"object"}]},"$editorDeleteComponent":{"params":[{"name":"id","type":"string"},{"name":"collection","type":"string"}]},"$designerDeleteComponent":{"params":[{"name":"id","type":"string"},{"name":"collection","type":"string"}]},"$designerDeleteType":{"params":[{"name":"id","type":"string"}]},"$designerCreateType":{"params":[{"name":"id","type":"string"},{"name":"type","type":"object"}]},"$editorUpdateType":{"params":[{"name":"id","type":"string"},{"name":"type","type":"object"}]},"$editorDeleteType":{"params":[{"name":"id","type":"string"}]},"$designerCreateSchema":{"params":[{"name":"id","type":"string"},{"name":"schema","type":"object"}]},"$editorUpdateSchema":{"params":[{"name":"id","type":"string"},{"name":"schema","type":"object"}]},"$editorUpdateSchemaId":{"params":[{"name":"oldId","type":"string"},{"name":"newId","type":"string"}]},"$designerDeleteSchema":{"params":[{"name":"id","type":"string"}]},"$designerCreateModel":{"params":[{"name":"id","type":"string"},{"name":"model","type":"object"}]},"$editorUpdateModel":{"params":[{"name":"id","type":"string"},{"name":"model","type":"object"}]},"$designerUpdateModel":{"params":[{"name":"id","type":"string"},{"name":"model","type":"object"}]},"$editorUpdateModelId":{"params":[{"name":"oldId","type":"string"},{"name":"newId","type":"string"}]},"$designerDeleteModel":{"params":[{"name":"id","type":"string"}]},"$editorUpdateSystem":{"params":[{"name":"id","type":"string"},{"name":"system","type":"object"}]},"$appLogDebug":{"params":[{"name":"message","type":"string"}]},"$appLogInfo":{"params":[{"name":"message","type":"string"}]},"$appLogWarn":{"params":[{"name":"message","type":"string"}]},"$appLogError":{"params":[{"name":"message","type":"string"}]},"$runtimeCreateComponent":{"params":[{"name":"collection","type":"string"},{"name":"component","type":"object"}]},"$runtimeDeleteComponent":{"params":[{"name":"id","type":"string"},{"name":"collection","type":"string"}]},"$runtimeUpdateComponent":{"params":[{"name":"id","type":"string"},{"name":"collection","type":"string"},{"name":"field","type":"string"},{"name":"value","type":"any"}]},"send":{"params":[{"name":"message","type":"message"}]},"$designerSetSystem":{"params":[{"name":"system","type":"object","mandatory":false,"default":{}}]}},"16b9d1ac2216ffe":{"_id":"16b9d1ac2216ffe","_name":"_Logger","_core":true,"level":{"type":"log","readOnly":false,"mandatory":false,"default":"warn"},"debug":{"params":[{"name":"message","type":"any"}]},"info":{"params":[{"name":"message","type":"any"}]},"warn":{"params":[{"name":"message","type":"any"}]},"error":{"params":[{"name":"message","type":"any"}]}}},"behaviors":{"g198c91f8601d02f":{"_id":"g198c91f8601d02f","component":"channel","state":"send","action":"function send(message) { \n  if (this.require('admin').designerWindow()) {\n    this.require('admin').designerWindow().postMessage(JSON.stringify(message), '*');\n  }\n}","useCoreAPI":false,"core":true},"h1b3891699319be4":{"_id":"h1b3891699319be4","component":"channel","state":"$designerCreateSchema","action":"function $designerCreateSchema(id, schema) { \n  if (schema && schema._name) {\n    this.require('logger').debug('analyzing ' + schema._name + ' model...');\n  }\n  this.require('logger').level('warn');\n  this.require('metamodel').schema(schema);\n  this.require('metamodel').create();\n  this.require('logger').level('debug');\n  if (schema && schema._name) {\n    this.require('logger').debug(schema._name + ' class has been created');\n  }\n}","useCoreAPI":false,"core":true},"w161ae196d51f585":{"_id":"w161ae196d51f585","component":"channel","state":"$editorUpdateSchema","action":"function $editorUpdateSchema(id, schema) { \n  if (schema && schema._name) {\n    this.require('logger').debug('analyzing ' + schema._name + ' model...');\n  }\n  \n  this.require('logger').level('warn');\n  this.require('metamodel').schema(schema);\n  this.require('metamodel').create();\n  this.require('logger').level('debug');\n  \n  if (schema && schema._name) {\n    this.require('logger').debug(schema._name + ' class has been updated');\n  }\n}","useCoreAPI":false,"core":true},"x12449136a811be2":{"_id":"x12449136a811be2","component":"channel","state":"$designerDeleteSchema","action":"function $designerDeleteSchema(id) { \n  this.require('logger').level('warn');\n  var search = $db._Schema.find({ '_id': id }),\n    modelName = '',\n    modelId = '';\n  \n  if (search.length) {\n    modelName = search[0]._name;\n    $db._Schema.remove({ '_id': id });\n  \n    search = $db._Model.find({ '_name': modelName });\n    if (search.length) {\n      modelId = search[0]._id;\n      $db._Model.remove({ '_id': modelId });\n      $component.removeFromMemory(modelName);\n    }\n  \n    search = $db._GeneratedModel.find({ '_name': modelName });\n    if (search.length) {\n      modelId = search[0]._id;\n      $db._GeneratedModel.remove({ '_id': modelId });\n      $component.removeFromMemory(modelName);\n    }\n    this.require('metamodel').create();\n  }\n  this.require('logger').level('debug');\t\n  \n  this.require('logger').debug(modelName + ' class has been deleted');\n}","useCoreAPI":true,"core":true},"h103b01d9591bbb4":{"_id":"h103b01d9591bbb4","component":"channel","state":"$designerCreateModel","action":"function $designerCreateModel(id, model) { \n  this.require('logger').level('warn');\n  this.require('metamodel').model(model);\n  this.require('metamodel').create();\n  this.require('logger').level('debug');\t\n}","useCoreAPI":false,"core":true},"r12c4e1d6cf1cf0e":{"_id":"r12c4e1d6cf1cf0e","component":"channel","state":"$editorUpdateModel","action":"function $editorUpdateModel(id, model) { \n  if (model && model._name) {\n    this.require('logger').debug('analyzing ' + model._name + ' model...');\n  }\n  \n  this.require('logger').level('warn');\n  this.require('metamodel').model(model);\n  this.require('metamodel').create();\n  this.require('logger').level('debug');\t\n  \n  if (model && model._name) {\n    this.require('logger').debug(model._name + ' has been updated');\n  }\n}","useCoreAPI":false,"core":true},"x1eb4c1d03b1ee34":{"_id":"x1eb4c1d03b1ee34","component":"channel","state":"$designerUpdateModel","action":"function $designerUpdateModel(id, model) { \n  this.require('logger').level('warn');\n  this.require('metamodel').model(model);\n  this.require('metamodel').create();\n  this.require('logger').level('debug');\t\n}","useCoreAPI":false,"core":true},"w1c68e1c7aa19326":{"_id":"w1c68e1c7aa19326","component":"channel","state":"$designerDeleteModel","action":"function $designerDeleteModel(id) { \n  this.require('logger').level('warn');\n  var search = $db._Model.find({ '_id': id }),\n    modelName = '',\n    modelId = '';\n  \n  if (search.length) {\n    modelName = search[0]._name;\n    $db._Model.remove({ '_id': id });\n    $component.removeFromMemory(modelName);\n  }\n  \n  search = $db._GeneratedModel.find({ '_name': modelName });\n  if (search.length) {\n    modelId = search[0]._id;\n    $db._GeneratedModel.remove({ '_id': modelId });\n    $component.removeFromMemory(modelName);\n  }\n  this.require('metamodel').create();\n  this.require('logger').level('debug');\n}","useCoreAPI":true,"core":true},"x1f6bc11b3816de0":{"_id":"x1f6bc11b3816de0","component":"channel","state":"$designerCreateType","action":"function $designerCreateType(id, type) { \n  this.require('logger').level('warn');\n  this.require('metamodel').type(type);\n  this.require('metamodel').create();\n  this.require('logger').level('debug');\t\n  \n  if (type && type.name) {\n    this.require('logger').debug(type.name + ' type has been created');\n  }\n}","useCoreAPI":false,"core":true},"m1ff4f11d19164c0":{"_id":"m1ff4f11d19164c0","component":"channel","state":"$editorUpdateType","action":"function $editorUpdateType(id, type) { \n  this.require('logger').level('warn');\n  this.require('metamodel').type(type);\n  this.require('metamodel').create();\n  this.require('logger').level('debug');\t\n  \n  if (type && type.name) {\n    this.require('logger').debug(type.name + ' type has been updated');\n  }\n}","useCoreAPI":false,"core":true},"u1e8bd17bdc15d6a":{"_id":"u1e8bd17bdc15d6a","component":"channel","state":"$editorDeleteType","action":"function $editorDeleteType(id) { \n  this.require('logger').level('warn');\n  $db._Type.remove({ 'name': id });\n  this.require('metamodel').create();\n  this.require('logger').level('debug');\t\n}","useCoreAPI":true,"core":true},"k18a311f76f1ff2a":{"_id":"k18a311f76f1ff2a","component":"channel","state":"$designerDeleteType","action":"function $designerDeleteType(id) { \n  var search = $db._Type.find({ 'name': id });\n  var type = search.length ? JSON.parse(JSON.stringify(search[0])) : null;\n  \n  this.require('logger').level('warn');\n  $db._Type.remove({ 'name': id });\n  this.require('metamodel').create();\n  this.require('logger').level('debug');\t\n  \n  if (type) {\n    this.require('logger').debug(type.name + ' type has been deleted');\n  }\n}","useCoreAPI":true,"core":true},"i1fe2e1f8fe1f3b7":{"_id":"i1fe2e1f8fe1f3b7","component":"channel","state":"$designerCreateComponent","action":"function $designerCreateComponent(collection, component) { \n  if ($db[collection]) {\n    $db[collection].insert(component);\t\n  } else {\n    if (component && component._id) {\n      this.require('logger').debug('can not create \\'' + component._id + '\\' component: ' + collection +' model does not exit');\n    }\n  }\n}","useCoreAPI":true,"core":true},"e1cc381f58818dd4":{"_id":"e1cc381f58818dd4","component":"channel","state":"$editorUpdateComponent","action":"function $editorUpdateComponent(id, collection, component) { \n  if ($db[collection]) {\n    $db[collection].update({ '_id': id }, component, { 'upsert': true });\t\n  } else {\n    this.require('logger').debug('can not update \\'' + id + '\\' component: ' + collection +' model does not exit');\n  }\n}","useCoreAPI":true,"core":true},"o1ed5a1768c181b2":{"_id":"o1ed5a1768c181b2","component":"channel","state":"$editorDeleteComponent","action":"function $editorDeleteComponent(id, collection) { \n  if ($db[collection]) {\n    $db[collection].remove({ '_id': id });\t\n  } else {\n    this.require('logger').debug('can not delete \\'' + id + '\\' component: ' + collection +' model does not exit');\n  }\n}","useCoreAPI":true,"core":true},"t18fe213b0718b38":{"_id":"t18fe213b0718b38","component":"channel","state":"$designerDeleteComponent","action":"function $designerDeleteComponent(id, collection) { \n  if ($db[collection]) {\n    $db[collection].remove({ '_id': id });\t\n  } else {\n    this.require('logger').debug('can not delete \\'' + id + '\\' component: ' + collection +' model does not exit');\n  }\n}","useCoreAPI":true,"core":true},"p1524e1d2c414a17":{"_id":"p1524e1d2c414a17","component":"channel","state":"$designerCreateBehavior","action":"function $designerCreateBehavior(behavior) { \n  $db._Behavior.insert(behavior);\t\n  \n  this.require('logger').debug(behavior.state  + ' behavior (\\'' + behavior.component + '\\' component) has been created');\n}","useCoreAPI":true,"core":true},"m154451abb8103f1":{"_id":"m154451abb8103f1","component":"channel","state":"$editorUpdateBehavior","action":"function $editorUpdateBehavior(id, behavior) { \n  if (this.require(id)) {\n    this.require(id).action(behavior.action);\n    if (behavior.state === 'start') {\n      this.require('logger').debug(behavior.state  + ' behavior of the system has been updated');\n      this.require('logger').debug('restarting the system...');\n      this.require(behavior.component).start();\n    } else {\n      this.require('logger').debug(behavior.state  + ' behavior (\\'' + behavior.component + '\\' component) has been updated');\n    }\n  }\telse {\n    this.require('logger').debug('can not update ' + behavior.state  + ' behavior (\\'' + behavior.component + '\\' component): the component does not exist');\n  }\n}","useCoreAPI":false,"core":true},"q131b819d531053f":{"_id":"q131b819d531053f","component":"channel","state":"$editorDeleteBehavior","action":"function $editorDeleteBehavior(id) { \n  $db._Behavior.remove({ '_id': id });\t\n}","useCoreAPI":true,"core":true},"h1214316cb61ea28":{"_id":"h1214316cb61ea28","component":"channel","state":"$designerDeleteBehavior","action":"function $designerDeleteBehavior(id) { \n  var search = $db._Behavior.find({ '_id': id });\n  var behavior = search.length ? JSON.parse(JSON.stringify(search[0])) : null;\n  \n  $db._Behavior.remove({ '_id': id });\n  \n  if (behavior) {\n    this.require('logger').debug(behavior.state  + ' behavior (\\'' + behavior.component + '\\' component) has been deleted');\n  }\n}","useCoreAPI":true,"core":true},"h109eb1b4ed148fd":{"_id":"h109eb1b4ed148fd","component":"channel","state":"$designerSync","action":"function $designerSync() { \n  var designerWindow = this.require('admin').designerWindow(),\n      system = null;\n\n  this.require('admin').designerWindow(null);\n  system = JSON.parse($db.exportSystem());\n  designerWindow = this.require('admin').designerWindow(designerWindow);\n\n  this.$appLoadSystem(system);\t\n}","useCoreAPI":true,"core":true},"w1a9961205712671":{"_id":"w1a9961205712671","component":"db","state":"insert","action":"function insert(event) { \n if (event.collection.indexOf('_') !== 0) {\n    this.require('channel').$runtimeCreateComponent(event.collection, event.document);\n  }\t\n}","useCoreAPI":false,"core":true},"j122701697c19935":{"_id":"j122701697c19935","component":"db","state":"remove","action":"function remove(event) { \n if (event.collection.indexOf('_') !== 0) {\n    this.require('channel').$runtimeDeleteComponent(event.id, event.collection);\n  }\t\n}","useCoreAPI":false,"core":true},"t118f61f6d0127e4":{"_id":"t118f61f6d0127e4","component":"db","state":"update","action":"function update(event) { \n  if (event.collection.indexOf('_') !== 0) {\n    this.require('channel').$runtimeUpdateComponent(event.id, event.collection, event.field, event.value);\n  }\t\n}","useCoreAPI":false,"core":true},"s1486715d9315862":{"_id":"s1486715d9315862","component":"channel","state":"init","action":"function init(conf) { \n  window.addEventListener('message', function message(event) {\n    var data = null;\n    try {\n      data = JSON.parse(event.data);\n      if (data &&\n        typeof data.event !== 'undefined' &&\n        typeof data.from !== 'undefined' &&\n        typeof data.data !== 'undefined') {\n          if (this.require('admin').designerWindow) {\n            this.require('admin').designerWindow(event.source);\n          }\n          $db._Message.insert(data);\n      }\n    } catch (e) {\n    }\n  }.bind(this), false);\t\n}","useCoreAPI":true,"core":true},"e10ba11978d122c5":{"_id":"e10ba11978d122c5","component":"admin","state":"init","action":"function init(conf) { \n  // for jquery compatibility in electron\n  if (typeof global !== 'undefined' && typeof window !== 'undefined') {\n    delete module;\n  }\n}","useCoreAPI":false,"core":true},"i139a61d4aa1bea7":{"_id":"i139a61d4aa1bea7","component":"logger","state":"info","action":"function info(message) { \n  if (this.level() === 'info' || this.level() === 'debug') {\n    var date = new Date(),\n      time = date.toTimeString(),\n      ms = date.getMilliseconds();\n\n    time = time.split(' ')[0].trim();\n    time = time.replace(':', 'h');\n    time = time.replace(':', 'm');\n    time = time.split('m')[0].trim();\n    time = time + ':' + ms;\n    \n    this.require('channel').$appLogInfo('[' + time + '] ' + message);\n  }\t\n}","useCoreAPI":false,"core":true},"r1c1841a98e1bc15":{"_id":"r1c1841a98e1bc15","component":"logger","state":"debug","action":"function debug(message) { \n  if (this.level() === 'debug') {\n    var date = new Date(),\n        time = date.toTimeString(),\n        ms = date.getMilliseconds();\n\n    time = time.split(' ')[0].trim();\n    time = time.replace(':', 'h');\n    time = time.replace(':', 'm');\n    time = time.split('m')[0].trim();\n    time = time + ':' + ms;\n    \n    this.require('channel').$appLogDebug('[' + time + '] ' + message);\n  }\t\n}","useCoreAPI":false,"core":true},"m1d30414ed912a2a":{"_id":"m1d30414ed912a2a","component":"logger","state":"error","action":"function error(message) { \n  var date = new Date(),\n      time = date.toTimeString(),\n      ms = date.getMilliseconds();\n\n  time = time.split(' ')[0].trim();\n  time = time.replace(':', 'h');\n  time = time.replace(':', 'm');\n  time = time.split('m')[0].trim();\n  time = time + ':' + ms;\n      \n  this.require('channel').$appLogError('[' + time + '] ' + message);\n}","useCoreAPI":false,"core":true},"d1d19f1ae9a12118":{"_id":"d1d19f1ae9a12118","component":"logger","state":"warn","action":"function warn(message) { \n  if (this.level() === 'info' || this.level() === 'warn' || this.level() === 'debug') {\n    var date = new Date(),\n        time = date.toTimeString(),\n        ms = date.getMilliseconds();\n\n      time = time.split(' ')[0].trim();\n      time = time.replace(':', 'h');\n      time = time.replace(':', 'm');\n      time = time.split('m')[0].trim();\n      time = time + ':' + ms;\n                \n    this.require('channel').$appLogWarn('[' + time + '] ' + message);\n  }\n}","useCoreAPI":false,"core":true},"a172ce13a3e1e8ff":{"_id":"a172ce13a3e1e8ff","component":"channel","state":"$designerSetSystem","action":"function $designerSetSystem(system) { \n  this.require('logger').level('info');\n\tthis.require('runtime').install(system);\n}","useCoreAPI":false,"core":true}},"types":{},"components":{"_Admin":{"admin":{"_id":"admin","_core":true,"designerWindow":null}},"_Channel":{"channel":{"_id":"channel"}},"_Database":{"db":{"_id":"db"}},"_Logger":{"logger":{"_id":"logger","level":"warn"}}},"_id":"18ed81de331252c"}