From 4e083231e775aa41e581c31f62ba20f8d726a162 Mon Sep 17 00:00:00 2001 From: Dimitar Nanov Date: Tue, 1 May 2018 16:22:57 +0300 Subject: [PATCH 1/5] Add externallyLoaded option to context, and load those separately --- lib/definitions/context.js | 2 ++ lib/structure/structureLoader.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/definitions/context.js b/lib/definitions/context.js index c19fbb7..da29b29 100644 --- a/lib/definitions/context.js +++ b/lib/definitions/context.js @@ -14,6 +14,8 @@ function Context (meta) { meta = meta || {}; + this.externallyLoaded = meta.externallyLoaded || false; + this.aggregates = []; } diff --git a/lib/structure/structureLoader.js b/lib/structure/structureLoader.js index be2923a..326c833 100644 --- a/lib/structure/structureLoader.js +++ b/lib/structure/structureLoader.js @@ -274,11 +274,22 @@ function analyze (dir, useLoaderExtensions, callback) { }); } +function reorderExternallyLoadedContexts (obj, ordered) { + obj.contexts.forEach(function (ctxItem) { + if (!ctxItem.value.externallyLoaded) + return; + ordered[ctxItem.name] = ctxItem.value; + }); +} + function reorderAggregates (obj, ordered) { var generalContext = new Context({ name: '_general' }); obj.aggregates.forEach(function (aggItem) { var foundCtx = _.find(obj.contexts, function (ctx) { + if (ctx.value.externallyLoaded) { + return false; + } if (aggItem.dottiedBase.indexOf('.') >= 0) { return aggItem.dottiedBase.indexOf(ctx.dottiedBase + '.') === 0; } else { @@ -288,6 +299,9 @@ function reorderAggregates (obj, ordered) { if (!foundCtx) { foundCtx = _.find(obj.contexts, function (ctx) { + if (ctx.value.externallyLoaded) { + return false; + } return ctx.dottiedBase === ''; }); } From 0a3a49671018b29722970173a9d3480592d6845d Mon Sep 17 00:00:00 2001 From: Dimitar Nanov Date: Tue, 1 May 2018 18:25:29 +0300 Subject: [PATCH 2/5] client.quit instead of client.end by redis aggregateLock --- lib/lock/databases/redis.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lock/databases/redis.js b/lib/lock/databases/redis.js index e0542f7..141392d 100644 --- a/lib/lock/databases/redis.js +++ b/lib/lock/databases/redis.js @@ -13,7 +13,7 @@ function Redis(options) { prefix: 'aggregatelock', retry_strategy: function (options) { return undefined; - }//, + } // heartbeat: 60 * 1000 }; @@ -135,7 +135,7 @@ _.extend(Redis.prototype, { this.stopHeartbeat(); if (this.client) { - this.client.end(true); + this.client.quit(); } this.emit('disconnect'); if (callback) callback(null, this); From 2797e2cad203a274bf36bf4fa831a02382c7dc02 Mon Sep 17 00:00:00 2001 From: Dimitar Nanov Date: Tue, 1 May 2018 18:30:43 +0300 Subject: [PATCH 3/5] same goes for commandBumper --- lib/bumper/databases/redis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bumper/databases/redis.js b/lib/bumper/databases/redis.js index cd6eb53..9dea1cc 100644 --- a/lib/bumper/databases/redis.js +++ b/lib/bumper/databases/redis.js @@ -136,7 +136,7 @@ _.extend(Redis.prototype, { this.stopHeartbeat(); if (this.client) { - this.client.end(true); + this.client.quit(); } this.emit('disconnect'); if (callback) callback(null, this); From 295239f85bf2a9ff4cc13f07f5e7afe507956e67 Mon Sep 17 00:00:00 2001 From: Dimitar Nanov Date: Tue, 1 May 2018 20:11:24 +0300 Subject: [PATCH 4/5] revert redis changes --- lib/bumper/databases/redis.js | 2 +- lib/lock/databases/redis.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bumper/databases/redis.js b/lib/bumper/databases/redis.js index 9dea1cc..cd6eb53 100644 --- a/lib/bumper/databases/redis.js +++ b/lib/bumper/databases/redis.js @@ -136,7 +136,7 @@ _.extend(Redis.prototype, { this.stopHeartbeat(); if (this.client) { - this.client.quit(); + this.client.end(true); } this.emit('disconnect'); if (callback) callback(null, this); diff --git a/lib/lock/databases/redis.js b/lib/lock/databases/redis.js index 141392d..936e71d 100644 --- a/lib/lock/databases/redis.js +++ b/lib/lock/databases/redis.js @@ -135,7 +135,7 @@ _.extend(Redis.prototype, { this.stopHeartbeat(); if (this.client) { - this.client.quit(); + this.client.end(true); } this.emit('disconnect'); if (callback) callback(null, this); From a7b715d8b5fd3a383ea7a756fdeeb680c4f16832 Mon Sep 17 00:00:00 2001 From: Dimitar Nanov Date: Tue, 1 May 2018 20:21:00 +0300 Subject: [PATCH 5/5] update readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index e86e09b..0abc9b6 100644 --- a/README.md +++ b/README.md @@ -653,6 +653,18 @@ After the initialization you can request the domain information: name: 'hr' }); +### Externally loaded context ( self-loaded ) + + A special option to define a context with all its aggregates, commands, events and rules exists by adding the externallyLoaded option to the context : + + module.exports = require('cqrs-domain').defineContext({ + // optional, default is the directory name + name: 'hr', + externallyLoaded: true + }); + + When doing so the context will be added 'as-is' to the domain, this means it won't go trough the normal tree loading and parsing process. + This option is aimed mainly at plugin developers, as it leaves the responsibility of structuring the domain right in the hand of the one defining the context ( most-probably a plug-in ). ## Aggregate