From 775f16ab62eedbf5a46473d94bf7ff79922ac47f Mon Sep 17 00:00:00 2001 From: Marcus Date: Mon, 27 May 2019 02:15:34 -0400 Subject: [PATCH] implemented _id and linking --- core/aqua.js | 4 ++-- core/compiler.js | 26 ++++++++++++++++++-------- tests/system/index.js | 17 +++++++++++------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/core/aqua.js b/core/aqua.js index 9d08a82..3b2460f 100644 --- a/core/aqua.js +++ b/core/aqua.js @@ -40,11 +40,9 @@ async function cliCompile(args) { if(!path.isAbsolute(args.index)) args.index = path.join(process.cwd(), args.index); if(!path.isAbsolute(args.cache)) args.cache = path.join(process.cwd(), args.cache); - let index = platformPrecompile(args); log.info('precompile completed'); - compile({ index: index, cache: args.cache @@ -63,6 +61,8 @@ function platformPrecompile(args) { const index = args.index; + if(!('Parameters' in index)) return index; + for(const key in args) { if(key in index.Parameters) { index.Parameters[key] = args[key]; diff --git a/core/compiler.js b/core/compiler.js index 8125fb1..1ac6c2d 100644 --- a/core/compiler.js +++ b/core/compiler.js @@ -1,6 +1,7 @@ const {Cache} = require('./cache.js'); const {retrieveModule} = require('./retrieveModule.js'); const {Signale} = require('signale'); +const uuid = require('uuid'); const log = new Signale({ scope: 'COMPILER' }); @@ -57,17 +58,26 @@ function compileParameters (index) { } function compileLinks (index) { - // TODO implement links + index = {...index}; - let entities = index.Entities; - - for(const key in index.Parameters) { - entities = recursiveReplace(entities, `\$${key}`, index.Parameters[key]); + //assign all _ids + for(const symbol in index.Entities) { + const ent = index.Entities[symbol]; + ent._id = uuid.v4(); } - return { - Entities: entities - }; + // loopback and replace all #links in Data with _ids + for(const symbol in index.Entities) { + let data = index.Entities[symbol].Data; + + for(const targetSymbol in index.Entities) { + data = recursiveReplace(data, `#${targetSymbol}`, index.Entities[targetSymbol]._id) + } + + index.Entities[symbol].Data = data; + } + + return index; } diff --git a/tests/system/index.js b/tests/system/index.js index 5c57035..6ca0548 100644 --- a/tests/system/index.js +++ b/tests/system/index.js @@ -3,17 +3,22 @@ const {Signale} = require('signale'); const log = new Signale({ scope: 'CLI' }); +let local = path.join(__dirname, './../modules/') module.exports = { - Parameters: { - Source: path.join(__dirname, './../modules/') - }, Entities: { - Tester: { + A: { Name: 'module', - From: '$Source', + From: local, Data: { - Thing: 5 + Thing: '#B' + } + }, + B: { + Name: 'module', + From: local, + Data: { + Thing: '#A' } } }