diff --git a/core/Collexion.js b/core/Collexion.js new file mode 100644 index 0000000..7186370 --- /dev/null +++ b/core/Collexion.js @@ -0,0 +1,54 @@ +const {Signale} = require('signale'); +const log = new Signale({ + scope: 'EXEC' +}); +const path = require('path'); +const fs = require('fs'); +const uuid = require('uuid'); + +const timeout = 3000; +const root = (typeof window === 'undefined' ? global : window) +const {Entity} = require('./entity.js') + + +class System { + constructor(cache) { + this.cache = cache; + this.entities = {}; + for(const uuid of cache.getInstances()) { + this.loadEntity(uuid) + } + } + + async send(name, destination, options) { + // log.debug(`sending ${name}`); + + if(!(destination in this.entities)) { + this.loadEntity(destination); + log.debug('loading entity...') + } + + this.entities[destination].dispatch(name, options); + } + + loadEntity(uuid) { + // log.debug(`spinning up ${uuid}`); + log.debug(uuid) + if(typeof require === 'function') { + let codePath = this.cache.getEntityCodePathFromUuid(uuid); + // log.debug(codePath) + let data = this.cache.getDataFromUuid(uuid); + let instanceData = this.cache.getInstanceFromUuid(uuid); + let userCode = require(codePath).entity; + this.entities[uuid] = new Entity(userCode, instanceData, this); + this.entities[uuid].start(); + log.debug('starting', uuid) + } else { + //TODO COMPLICATED EVAL SHIT, MIRRORING REQUIRE FUNCTIONALITY + } + } + + +} + +module.exports = {System}; \ No newline at end of file diff --git a/core/ConfigParser.js b/core/ConfigParser.js new file mode 100644 index 0000000..e69de29 diff --git a/core/system.js b/core/system.js index cd4e8ef..7186370 100644 --- a/core/system.js +++ b/core/system.js @@ -10,7 +10,8 @@ const timeout = 3000; const root = (typeof window === 'undefined' ? global : window) const {Entity} = require('./entity.js') -module.exports.System = class System { + +class System { constructor(cache) { this.cache = cache; this.entities = {}; @@ -48,4 +49,6 @@ module.exports.System = class System { } -} \ No newline at end of file +} + +module.exports = {System}; \ No newline at end of file diff --git a/package.json b/package.json index 458761d..43def17 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { - "name": "aquatin", - "version": "1.0.0", + "name": "collexion", + "version": "0.0.1", "description": "", - "main": "index.js", + "main": "./core/Collexion.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "tsc --watch" }, "repository": { "type": "git", @@ -16,12 +17,14 @@ "url": "https://github.com/marcus13345/AquaTin/issues" }, "bin": { - "aqua": "core/aqua.js" + "clx": "core/aqua.js" }, "homepage": "https://github.com/marcus13345/AquaTin#readme", "dependencies": { + "aquatin": "file:.", "rimraf": "^2.6.3", "signale": "^1.4.0", + "typescript": "^3.5.3", "uuid": "^3.3.2", "yargs": "^13.2.4" } diff --git a/test.js b/test.js new file mode 100644 index 0000000..847e332 --- /dev/null +++ b/test.js @@ -0,0 +1,3 @@ +const {System} = require('aquatin/core/system.js'); + +console.log(System) \ No newline at end of file diff --git a/tests/pingpong/index.js b/tests/pingpong/index.js new file mode 100644 index 0000000..0f237c4 --- /dev/null +++ b/tests/pingpong/index.js @@ -0,0 +1,23 @@ +const = require('.'); +console.log(ref) + +// const ExampleModule = require('./module.js.js'); + +// module.exports = { +// Entities: { +// A: { +// Code: ExampleModule, +// Data: { +// thing: ref('B'), +// boop: true +// } +// }, +// B: { +// Code: ExampleModule, +// Data: { +// thing: ref('B') +// } +// } +// } +// } + diff --git a/tests/pingpong/index_old.js b/tests/pingpong/index_old.js new file mode 100644 index 0000000..58e2a93 --- /dev/null +++ b/tests/pingpong/index_old.js @@ -0,0 +1,22 @@ +const path = require('path'); +let local = path.join(__dirname, './../modules/') + +module.exports = { + Entities: { + A: { + Name: 'module', + From: local, + data: { + thing: '#B', + boop: true + } + }, + B: { + Name: 'module', + From: local, + data: { + thing: '#A' + } + } + } +} \ No newline at end of file diff --git a/tests/modules/module.js b/tests/pingpong/module.js similarity index 100% rename from tests/modules/module.js rename to tests/pingpong/module.js diff --git a/tests/system/index.js b/tests/system/index.js index 58e2a93..f7c6c96 100644 --- a/tests/system/index.js +++ b/tests/system/index.js @@ -1,22 +1,24 @@ const path = require('path'); -let local = path.join(__dirname, './../modules/') + +const ref = require('./node_modules/aqua').Reference; + +const ExampleModule = require('./module.js'); module.exports = { Entities: { A: { - Name: 'module', - From: local, - data: { - thing: '#B', + Code: ExampleModule, + Data: { + thing: ref('B'), boop: true } }, B: { - Name: 'module', - From: local, - data: { - thing: '#A' + Code: ExampleModule, + Data: { + thing: ref('B') } } } -} \ No newline at end of file +} + diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..36a22a1 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "include": [ + "core/*" + ], + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "sourceMap": true + } +} + + + +