Closed blissi closed 6 years ago
separate repo is ok... you can post it 😉
Ok, done. For all other guys: when DefinitelyTyped takes over the mappings, they can be installed by
npm i --save-dev @types/cqrs-domain
@blissi the typescript mappings seems outdated. below sample passed the type check but failed in runtime:
import * as Domain from 'cqrs-domain'
let domain = Domain({
domainPath: '/tmp/demo',
})
domain.onEvent(ev => {
console.log({ev})
});
domain.init((err, warnings) => {
console.log({err, warnings})
})
// console.log(domain.getInfo());
Received Error: Error: No structure loaded for /tmp/demo!
/tmp/demo is an empty folder
@beenotung If it is an empty folder, how should a structure be loaded? The mappings are still fine in this regard, just create a structure as described in the documentation.
@blissi im stuck when trying to throw meaningful errors when precondition fail by instantiating a BusinessRuleError and setting arbitrary values in its more prop. It seems that BusinessRuleError is not defined in your types, any plan to add them?
some background: reading the docs the suggested way to customize the error for pre conditions seems to be either setting a message in error (quite limited but i could live with that) and adding inso as second param of BusinessRuleError (id prefer)
return callback('not personalized');
// or
// return callback(new Error('not personalized'));
// or
// return callback(new Error()); // if no error message is defined then the description will be taken
// or
// return callback(new require('cqrs-domain').BusinessRuleError('not personalized', { /* more infos */ }));
anything else would get moved to a BusinessRuleError by
function handleError (err) {
debug(err);
if (_.isString(err)) {
if (_.isEmpty(err)) {
err = self.description;
}
err = new BusinessRuleError(err);
} else if (err instanceof BusinessRuleError) {
// do nothing
} else {
err = new BusinessRuleError(err.message || self.description);
}
callbacked = true;
callback(err);
}
Hallo Adriano, I created TypeScript mappings for cqrs-domain: https://github.com/blissi/DefinitelyTyped/blob/master/types/cqrs-domain/index.d.ts
Are you interested in integrating these into your lib? Otherwise I would post it to @types.
Steven