Releases: 4lessandrodev/rich-domain
Releases · 4lessandrodev/rich-domain
v1.17.0
1.17.0 - 2022-01-21
Changed
- ValueObject, Entity, Aggregate:
clone
method now returns an instance insteadResult
- ValueObject, Entity, Aggregate:
set
andchange
method now returnstrue
if the value has changed and returnsfalse
if the value has not changed.
- Util: added method date. pull request 32
onst date = new Date('2001-09-09T01:46:39.999Z');
const result = Utils.date(date).add(5).days();
result.toISOString()
> "2001-09-14T01:46:39.999Z"
- Aggregate, Entity, ValueObject: added
util
method to instance. - Util: added class to domain with some utils functions. pull request 31
Example:
// remove spaces from string
const text = " Some Text With Space ";
const result = Utils.string(text).removeSpaces();
> "SomeTextWithSpace"
// remove special chars
const text = "Some #Text @With Special&* Chars";
const result = Utils.string(text).removeSpecialChars();
> "Some Text With Special Chars"
// calculate values as number
const result = Utils.number(100).multiplyBy(3);
> 300
// also works case leak value as string
const result = Utils.number("100").multiplyBy("3");
> 300
// instance available on domain instances
interface Props { value: number };
class Example extends ValueObject<Props>{
private constructor(props: Props){
super(props)
}
sum(x: number): number {
const current = this.props.value;
return this.util.number(current).sum(x);
}
}
Added
- Aggregate: added method
dispatchEvent
to handle domain events from aggregate instance. - Validator: added method
isSpecialChar
andhasSpecialChar
to check special character.
// dispatch event from aggregate instance
// dispatch all events for aggregate
product.dispatchEvent();
// OR
// dispatch an specific event name
product.dispatchEvent("ProductCreated");
Utils function available to domain instances, ValueObject, Entity and Aggregate
const result = Utils.date(date).add(5).minutes();
result.toISOString()
> "2001-09-09T01:51:39.999Z"
const result = Utils.number('70' as any).sum('7' as any);
> 77
const result = Utils.number(70).multiplyBy(7);
> 490
const target = "Hi, My Name Is Jane Doe, I am 18 years old";
const char = 'a';
const value = '4';
const result = Utils.string(target).replace(char).to(value);
> "Hi, My N4me Is J4ne Doe, I 4m 18 ye4rs old"
What's Changed
- Feat/equal by @4lessandrodev in #28
- chore(deps-dev): bump rimraf from 3.0.2 to 4.0.7 by @dependabot in #29
- Feat/validator by @4lessandrodev in #30
- Feat/util by @4lessandrodev in #31
- feat(utils): added date on util class to domain by @4lessandrodev in #32
Full Changelog: v1.16.0...v1.17.0
v1.16.0
1.16.0 - 2022-01-12
Added
- Entity: added method
isEqual
to compare current instance with another one. - ValueObject: added method
isEqual
to compare current instance with another one. Issue 27
class EntityExample extends Entity<Props>{
private constructor(props: Props) {
super(props)
}
public static create(props: Props): Result<EntityExample> {
return Ok(new EntityExample(props));
}
}
const a = EntityExample.create({...props, id }).value();
const b = EntityExample.create({...props, id }).value();
console.log(a.isEqual(b));
> true
v1.15.0
1.15.0 - 2022-12-25
Changed
- value-object: mark set function as deprecated
- value-object: mark change function as deprecated
- validator: change methods for string (hasLengthBetween - now validate only interval)
- validator: rename method isPair to isEven
Added
- validator - string added method hasLengthBetweenOrEqual
- validator - number isBetweenOrEqual
The function still works, but it is marked as deprecated. show warning if using.
v1.14.6
- With Aggregate entities conversion to a simple object
- With Domain events dispatchAll option
- Minor bug fix
stable
1.9.0 v1.9.0
beta
beta version