1.0.1 • Published 8 months ago
@hexadrop/aggregate-root v1.0.1
Installation
npm install --save @hexadrop/aggregate-root
Using bun
bun add @hexadrop/aggregate-root
What it does
- Default export is an abstract class
AggregateRoot
. This class provides the following:- A
record(...events: DomainEvent[])
method to record events. - A
pullDomainEvents(): DomainEvent[]
method to get uncommitted events. - An abstract
toPrimitives(): Primitives<this>
method to convert the aggregate root to primitives.
- A
How to use
import AggregateRoot from '@hexadrop/aggregate-root';
import type { DomainEventParams } from '@hexadrop/event';
import DomainEvent from '@hexadrop/event';
import type { Primitives } from '@hexadrop/types/primitives';
class MockEvent extends DomainEvent {
static override EVENT_NAME = 'event';
readonly foo: string;
constructor({ foo, ...params }: DomainEventParams<MockEvent>) {
super(MockEvent.EVENT_NAME, params);
this.foo = foo;
}
}
class MockAggregateRoot extends AggregateRoot {
readonly foo: string;
constructor(primitives: Primitives<MockAggregateRoot>) {
super();
this.foo = primitives.foo;
}
static create(foo: string): MockAggregateRoot {
const aggregateRoot = new MockAggregateRoot({ foo });
aggregateRoot.record(new MockEvent({ foo }));
return aggregateRoot;
}
override toPrimitives(): Primitives<MockAggregateRoot> {
return {
foo: this.foo,
};
}
}
Hexatool Code Quality Standards
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
2.0.0-beta.17
8 months ago
2.0.0-beta.16
8 months ago
2.0.0-beta.11
1 year ago
2.0.0-beta.15
9 months ago
2.0.0-beta.14
11 months ago
2.0.0-beta.13
12 months ago
2.0.0-beta.12
1 year ago
2.0.0-beta.10
1 year ago
2.0.0-beta.9
1 year ago
2.0.0-beta.8
1 year ago
2.0.0-beta.7
1 year ago
2.0.0-beta.2
1 year ago
2.0.0-beta.1
1 year ago
2.0.0-beta.6
1 year ago
2.0.0-beta.5
1 year ago
2.0.0-beta.4
1 year ago
2.0.0-beta.3
1 year ago
2.0.0-beta.0
1 year ago
1.0.1
2 years ago
1.0.0
2 years ago
1.0.0-beta.2
2 years ago
1.0.0-beta.1
2 years ago
1.0.0-beta.0
2 years ago