https://github.com/timreynolds/js-domain
Base classes and ts declarations for using the domain model pattern with DDD in js
https://github.com/timreynolds/js-domain
ddd ddd-patterns domain-driven-design events javascript typescript
Last synced: about 1 month ago
JSON representation
Base classes and ts declarations for using the domain model pattern with DDD in js
- Host: GitHub
- URL: https://github.com/timreynolds/js-domain
- Owner: timReynolds
- License: mit
- Created: 2017-08-26T16:09:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-08-01T11:51:37.000Z (almost 4 years ago)
- Last Synced: 2025-04-23T01:56:41.327Z (about 1 month ago)
- Topics: ddd, ddd-patterns, domain-driven-design, events, javascript, typescript
- Language: TypeScript
- Size: 183 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
JS DDD Classes
=========================[](https://travis-ci.org/timReynolds/js-domain)
[](https://coveralls.io/github/timReynolds/js-domain?branch=master)A set of base classes used to implement [DDD](https://en.wikipedia.org/wiki/Domain-driven_design) style [domain model](https://martinfowler.com/eaaCatalog/domainModel.html) pattern in JavaScript.
# Classes
Below outlines the classes provided in this package and the functionality encapsulated in each.
## Value Object
> Objects that matter only as the combination of their attributes. Two value objects with the same values for all their attributes are considered equal.Provides a createdOn date which is can either be set via the constructor or defaults to Moment utc.
## Entity
> Objects that have a distinct identity that runs through time and different representations.Extends ```ValueObject``` but provides an id to distinguishes the objects identity throughout time. Defaulted to a v4 GUID when not provided.
## Aggregate Root
> Cluster of domain objects that can be treated as a single unit and the basic element of transfer of data storage.Extends ```Entity``` with the additional responsibility of tracking and queuing ```Events```.
Within these classes the Aggregate takes responsibility for eventing for any entity it manages. Events are stored within the class and made accessible vis the ```enqueuedEvents``` method. The advantages of this approach are;
* Class isn't coupled to a publisher
* Events can be batched processed
* Events can be encapsulated within a transactional boundary## Event
> Captures the memory of something interesting which affects the domainUsed to provide a consistent interface for events from the domain expecting a ```type``` and ```data``` properties via the constructor. The following common event properties are default unless provided;
* id
* correlationId
* raisedOnIntended to be extended by specific event classes that include data validation.
#Example Usage
All classes are exposed at root level.
```
const { ValueObject } = require('@reynolds/domain');
class Example extends ValueObject {
```As are typescript declarations
```
const { ICreatedOn } = require('@reynolds/domain');
class Example implements ICreatedOn {}
```