Hexagonal architecture utils library
npm install @hexadrop/aggregate-root
Opinionated aggregate root base class for DDD
``bash`
npm install --save @hexadrop/aggregate-root
Using bun
`bash`
bun add @hexadrop/aggregate-root
- Default export is an abstract class AggregateRoot. This class provides the following:record(...events: DomainEvent[])
- A method to record events.pullDomainEvents(): DomainEvent[]
- A method to get uncommitted events.toPrimitives(): Primitives
- An abstract method to convert the aggregate root to primitives.
`typescript
import AggregateRoot from '@hexadrop/aggregate-root';
import DomainEvent from '@hexadrop/event';
import type { Primitives } from '@hexadrop/types/primitives';
class MockEvent extends DomainEvent {
static override EVENT_NAME = 'event';
constructor(
readonly foo: string,
aggregateId: string
) {
super(MockEvent.EVENT_NAME, aggregateId);
}
}
class MockAggregateRoot extends AggregateRoot {
readonly foo: string;
constructor(primitives: Primitives
super();
this.foo = primitives.foo;
}
static create(foo: string): MockAggregateRoot {
const aggregateRoot = new MockAggregateRoot({ foo });
aggregateRoot.record(new MockEvent(foo, 'aggregateId'));
return aggregateRoot;
}
override toPrimitives(): Primitives
return {
foo: this.foo,
};
}
}
``
Publishing this package we are committing ourselves to the following code quality standards:
- Respect Semantic Versioning: No breaking changes in patch or minor versions
- No surprises in transitive dependencies: Use the bare minimum dependencies needed to meet the purpose
- One specific purpose to meet without having to carry a bunch of unnecessary other utilities
- Tests as documentation and usage examples
- Well documented README showing how to install and use
- License favoring Open Source and collaboration