cqrs-domain
Advanced tools
Comparing version 2.13.1 to 2.14.0
@@ -9,2 +9,3 @@ var debug = require('debug')('domain'), | ||
commandBumper = require('./bumper'), | ||
customLoader = require('./structure/customLoader'), | ||
structureLoader = require('./structure/structureLoader'), | ||
@@ -46,2 +47,14 @@ attachLookupFunctions = require('./structure/treeExtender'), | ||
function createStructureLoader (options) { | ||
if (options) { | ||
if (!_.isFunction(options)) { | ||
var err = new Error('"options.structureLoader" is not a valid structure loader method'); | ||
debug(err); | ||
throw err; | ||
}; | ||
return customLoader(options); | ||
} | ||
return structureLoader; | ||
} | ||
function isValidAggregateLock (obj) { | ||
@@ -106,3 +119,3 @@ // TODO: check each method's signature? | ||
if (!options.domainPath) { | ||
var err = new Error('Please provide domainPath in options'); | ||
var err = new Error('Please provide domainPath or domainLoader in options'); | ||
debug(err); | ||
@@ -118,4 +131,6 @@ throw err; | ||
options.useLoaderExtensions = options.useLoaderExtensions || false | ||
options.useLoaderExtensions = options.useLoaderExtensions || false; | ||
this.structureLoader = createStructureLoader(options.structureLoader); | ||
this.eventStore = createEventStore(options.eventStore); | ||
@@ -174,2 +189,4 @@ | ||
/** | ||
@@ -262,2 +279,20 @@ * Inject definition for command structure. | ||
/** | ||
* Inject custom structure loader function | ||
* @param {Function} fn The function to be injected. | ||
* @returns {Domain} to be able to chain... | ||
*/ | ||
defineStructureLoader: function (fn) { | ||
if (!fn || !_.isFunction(fn)) { | ||
var err = new Error('Please pass a valid function!'); | ||
debug(err); | ||
throw err; | ||
} | ||
this.structureLoader = customLoader(fn); | ||
return this; | ||
}, | ||
/** | ||
* Inject function for for event notification. | ||
@@ -387,2 +422,3 @@ * @param {Function} fn the function to be injected | ||
async.series([ | ||
@@ -392,3 +428,3 @@ // load domain files... | ||
debug('load domain files..'); | ||
structureLoader(self.options.domainPath, self.validatorExtension, self.options.useLoaderExtensions, function (err, tree, warns) { | ||
self.structureLoader(self.options.domainPath, self.validatorExtension, self.options.useLoaderExtensions, function (err, tree, warns) { | ||
if (err) { | ||
@@ -395,0 +431,0 @@ return callback(err); |
{ | ||
"author": "adrai", | ||
"name": "cqrs-domain", | ||
"version": "2.13.1", | ||
"version": "2.14.0", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -262,2 +262,21 @@ | ||
## Using custom structure loader function | ||
You can also replace the built-in structure loader with one that suits your needs. | ||
To do that, you need to include a loading method in the options object passed to the domain constructor. | ||
// options will contain a the domainPath, validatorExtension, and useLoaderExtensions options passed to the constructor | ||
// ass well as a definition object containing all the constructors of the domain components ( Context, Aggregate etc. ) | ||
function myCustomLoader(options) { | ||
return { | ||
myContext: new Context({ name: 'myContext' }).addAggregate(new Aggregate({ name : 'agg' }, function(){}).addCommand({ name: 'cmd' }, function(){})) | ||
} | ||
// or, more probably | ||
return myExternalCoolLoader(options.domainPath, options.definitions); | ||
} | ||
var domain = require('cqrs-domain')({ | ||
domainPath: '/path/to/my/files', | ||
structureLoader: myCustomLoader | ||
}); | ||
## Exposed errors | ||
@@ -264,0 +283,0 @@ You can use this for example in you custom command handlers. |
@@ -0,1 +1,4 @@ | ||
## [v2.14.0](https://github.com/adrai/node-cqrs-domain/compare/v2.13.1...v2.14.0) | ||
- add option to add custom structureLoader implementation[#125](https://github.com/adrai/node-cqrs-domain/pull/125) thanks to [nanov](https://github.com/nanov) | ||
## [v2.13.1](https://github.com/adrai/node-cqrs-domain/compare/v2.12.3...v2.13.1) | ||
@@ -2,0 +5,0 @@ - Introduce externallyLoaded option to context, and load those separately [#121](https://github.com/adrai/node-cqrs-domain/pull/121) thanks to [nanov](https://github.com/nanov) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
285135
46
6612
1274