2.0.1 • Published 10 months ago

@hexadrop/aggregate-root v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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.

How to use

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<MockAggregateRoot>) {
    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<MockAggregateRoot> {
    return {
      foo: this.foo,
    };
  }
}

Hexadrop 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.1

10 months ago

2.0.0

10 months ago

2.0.0-beta.17

12 months ago

2.0.0-beta.16

1 year ago

2.0.0-beta.11

1 year ago

2.0.0-beta.15

1 year ago

2.0.0-beta.14

1 year ago

2.0.0-beta.13

1 year ago

2.0.0-beta.12

1 year ago

2.0.0-beta.10

1 year ago

2.0.0-beta.9

2 years ago

2.0.0-beta.8

2 years ago

2.0.0-beta.7

2 years ago

2.0.0-beta.2

2 years ago

2.0.0-beta.1

2 years ago

2.0.0-beta.6

2 years ago

2.0.0-beta.5

2 years ago

2.0.0-beta.4

2 years ago

2.0.0-beta.3

2 years ago

2.0.0-beta.0

2 years 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