@event-nest/core 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,239 @@
1
- # core
1
+ # Event Nest
2
+ A collection of [nest.js](https://nestjs.com/) libraries to help you build applications based on event sourcing architecture.
2
3
 
3
- This library was generated with [Nx](https://nx.dev).
4
+ ## Description
5
+ Event Nest is a collection of libraries based on nest.js that assists in implementing the core concepts of event sourcing:
6
+ * Saving events in a persistent storage
7
+ * Utilizing the saved events to trigger side effects, such as updating your read model
8
+ * Replaying events to reconstruct the state of your application
4
9
 
5
- ## Building
10
+ Given that event sourcing is commonly used in conjunction with [CQRS](https://martinfowler.com/bliki/CQRS.html) and [Domain Driven Design](https://en.wikipedia.org/wiki/Domain-driven_design), these libraries adopt principles from these architectural patterns.
6
11
 
7
- Run `nx build core` to build the library.
12
+ It would also probably help to make some distinctions about what Event Nest is not :
13
+ * It is not a framework, it is a set of libraries which are designed to be used with nest.js.
14
+ * It is not an ORM, if you want an ORM to define simple models, there are far better solutions out there.
15
+ * It is not a library for establishing event-based communication between services.
16
+ * **Although the code is covered by tests, the library is not widely tested in production. Use it at your own risk.**
8
17
 
9
- ## Running unit tests
18
+ ## Why?
19
+ Implementing event sourcing in an application can be challenging, particularly when combined with CQRS and DDD.
20
+
21
+ Nest.js provides a [fantastic module](https://github.com/nestjs/cqrs) for CQRS but after using it for a while I thought that maybe some things could be improved.
22
+ Furthermore, these improvements can't be added to the official module due to its lightweight and abstract nature.
23
+ For instance, the official module lacks a specific way of persisting the events to a storage.
24
+
25
+ This is where Event Nest comes into play. In fact, a significant portion of the code in Event Nest is influenced by how things are implemented in the official module.
26
+
27
+ This project evolved into a library after I used the official module with my improvements in a few projects and I thought that it could be useful to other people. To make things
28
+ simpler, the library is not depending on the official module, so you can use it without having to worry about conflicts.
29
+
30
+ ## Getting Started
31
+ Depending on the storage solution you intend to use, you will need to install the corresponding packages.
32
+ At the moment, only MongoDB is supported, hopefully soon there will be more.
33
+
34
+ ```bash
35
+ npm install --save @event-nest/core @event-nest/mongodb
36
+ ```
37
+ After installation, import the `EventNestMongoDbModule` to your nest.js application :
38
+ ```typescript
39
+ import { Module } from "@nestjs/common";
40
+ import { EventNestMongoDbModule } from "@event-nest/mongodb";
41
+
42
+ @Module({
43
+ imports: [
44
+ EventNestMongoDbModule.register({
45
+ connectionUri: "mongodb://localhost:27017/example",
46
+ aggregatesCollection: "aggregates-collection",
47
+ eventsCollection: "events-collection"
48
+ }),
49
+ ],
50
+ })
51
+ export class AppModule {}
52
+ ```
53
+ The collection settings define which MongoDB collections will be used to store the aggregates and the events.
54
+ Use any collection you want but be sure to create it before running the application.
55
+
56
+
57
+
58
+ ## Concepts
59
+ ### Aggregate Root
60
+ An [aggregate root](https://stackoverflow.com/questions/1958621/whats-an-aggregate-root) is a concept from Domain Driven Design. It is a domain object that is responsible for maintaining the consistency of the aggregate.
61
+ To achieve this, the aggregate root should expose methods which encapsulate its behaviour. Any method that needs to update the state, should also append an event to the aggregate root's event stream.
62
+
63
+ ### Event
64
+ An event is a representation of something that has happened in the past. It is identified by a unique name, and it may contain additional data that will be persisted with the event.
65
+
66
+ Each event can be used for three purposes :
67
+ * It will be persisted so that it can be used to reconstruct the state of an aggregate root
68
+ * It will be passed to any internal subscribers that need to react to this event (e.g. updating the read model)
69
+ * When it's time to recreate the aggregate root, the event will be processed by the correct method in the aggregate root
70
+
71
+ Enough with the theory, let's see an example that includes all of the above.
72
+
73
+ #### Example
74
+
75
+ ```typescript
76
+ import { RegisteredEvent } from "@event-nest/core";
77
+
78
+ @RegisteredEvent("user-created-event")
79
+ export class UserCreatedEvent {
80
+ constructor(public name: string, public email: string) {}
81
+ }
82
+ ```
83
+
84
+ ```typescript
85
+ import { RegisteredEvent } from "@event-nest/core";
86
+
87
+ @RegisteredEvent("user-updated-event")
88
+ export class UserUpdatedEvent {
89
+ constructor(public newName: string) {}
90
+ }
91
+ ```
92
+
93
+ We start this example by defining two simple events for a user: a creation event and an update event. Each one has its own data, and they are identified by a unique name which is set with the `@RegisteredEvent` decorator.
94
+
95
+ ```typescript
96
+ import { AggregateRoot, AggregateRootName, EventProcessor, StoredEvent } from "@event-nest/core";
97
+
98
+ @AggregateRootName("User")
99
+ export class User extends AggregateRoot {
100
+ private _name: string;
101
+ private _email: string;
102
+
103
+ private constructor(id: string) {
104
+ super(id);
105
+ }
106
+
107
+ public static createNew(id: string, name: string, email: string): User {
108
+ const user = new User(id);
109
+ const event = new UserCreatedEvent(name, email);
110
+ user.processUserCreatedEvent(event);
111
+ user.append(event);
112
+ return user;
113
+ }
114
+
115
+ public static fromEvents(id: string, events: Array<StoredEvent>): User {
116
+ const user = new User(id);
117
+ user.reconstitute(events);
118
+ return user;
119
+ }
120
+
121
+ public update(newName: string) {
122
+ const event = new UserUpdatedEvent(newName);
123
+ this.processUserUpdatedEvent(event);
124
+ this.append(event);
125
+ }
126
+
127
+ @EventProcessor(UserCreatedEvent)
128
+ private processUserCreatedEvent = (event: UserCreatedEvent) => {
129
+ this._name = event.name;
130
+ this._email = event.email;
131
+ };
132
+
133
+ @EventProcessor(UserUpdatedEvent)
134
+ private processUserUpdatedEvent = (event: UserUpdatedEvent) => {
135
+ this._name = event.newName;
136
+ };
137
+
138
+ }
139
+ ```
140
+
141
+ Next, we define the aggregate root for the user. There's a lot going on here so let's break it down.
142
+
143
+ First of all, the class has to extend the `AggregateRoot` class, and it has to be decorated with the `@AggregateRootName` decorator.
144
+ The name is required to associate persisted events with the correct aggregate root when retrieving them from storage.
145
+
146
+ Now let's talk about the constructor. TypeScript doesn't allow us to define multiple constructors. So if we have two ways of creating an object, we could use static methods as factories.
147
+ In our case, we have the following creation cases :
148
+ * The user is new, and we need to create it from scratch. In that case, we create a new `UserCreatedEvent` event, and we `append` it to the aggregate root's event stream.
149
+ * The user already exists. In that case we need to recreate the aggregate root from the events that have been persisted. We do that by calling the `reconstitute` method.
150
+
151
+ The `reconstitute` method will initiate the event processing based on the events order.
152
+
153
+ To process each event, we have defined two private methods which are decorated with the `@EventProcessor` decorator. Each method will be called when the corresponding event is retrieved, and it's ready to be processed.
154
+ This is the place to update the object's internal state based on the event's data. **Make sure that these methods are defined as arrow functions, otherwise they won't be called.**
155
+
156
+
157
+ Finally, we define an `update` method which is the place to run any business logic we need and append the corresponding event (`UserUpdatedEvent`) to the event stream.
158
+
159
+ It's important to note that the append method is not saving the event. All the appended events can be saved by calling the `commit` method on the aggregate root.
160
+
161
+ ```typescript
162
+ import { EVENT_STORE, EventStore } from "@event-nest/core";
163
+
164
+ @Injectable()
165
+ export class UserService {
166
+ constructor(@Inject(EVENT_STORE) private eventStore: EventStore) {}
167
+
168
+ async createUser(name: string, email: string) {
169
+ const user = User.createNew(new ObjectId().toHexString(), name, email);
170
+ const userWithPublisher = this.eventStore.addPublisher(user);
171
+ await userWithPublisher.commit();
172
+ return user.id;
173
+ }
174
+
175
+ async updateUser(id: string, newName: string) {
176
+ const events = await this.eventStore.findByAggregateRootId(User, id);
177
+ const user = User.fromEvents(id, events);
178
+ const userWithPublisher = this.eventStore.addPublisher(user);
179
+ user.update(newName);
180
+ await userWithPublisher.commit();
181
+ }
182
+ }
183
+ ```
184
+
185
+ The final piece of the puzzle is a nest.js service that will manage the process.
186
+
187
+ We start by injecting the `EventStore`, which will be used to retrieve persisted events.
188
+
189
+ Additionally, since the aggregate root classes are not managed by the nest.js dependency injection system, we need to connect them to the event store by calling the `addPublisher` method. This will allow the
190
+ `commit` method to work as expected.
191
+
192
+ ### Domain Event Subscription
193
+ When working with event sourcing, you will likely need a way of updating other parts of your system when an event is persisted. For example, you may have a read model for users that needs to be updated when a user is created or updated.
194
+
195
+ To achieve this, you can implement a service decorated with the `@DomainEventSubscription` decorator. This decorator takes a list of events that the service is interested in, and it automatically subscribes to them when the service is initialized.
196
+
197
+ To ensure that the method is implemented correctly, you can use the `OnDomainEvent` interface.
198
+
199
+ #### Example
200
+ ```typescript
201
+ import { AggregateRootAwareEvent, DomainEventSubscription, OnDomainEvent } from "@event-nest/core";
202
+
203
+ @Injectable()
204
+ @DomainEventSubscription(UserCreatedEvent, UserUpdatedEvent)
205
+ export class UserEventSubscription implements OnDomainEvent<UserCreatedEvent | UserUpdatedEvent> {
206
+
207
+ onDomainEvent(event: AggregateRootAwareEvent<UserCreatedEvent | UserUpdatedEvent>): Promise<unknown> {
208
+ //Here you can create/update your read model based on the event and your custom logic.
209
+ return Promise.resolve(undefined);
210
+ }
211
+
212
+ }
213
+ ```
214
+
215
+ If there are multiple subscription services for the same event, they will be executed in parallel.
216
+ However, if there are multiple events that the service is subscribed to, they will be executed sequentially based on the order they were emitted.
217
+
218
+ This is the default behaviour because there are cases where the logic may depend on the completion of the previous event. If you want better performance
219
+ and your logic doesn't depend on the order of the events, you can change this setting when you import the module.
220
+
221
+ ```typescript
222
+ @Module({
223
+ imports: [
224
+ EventNestMongoDbModule.register({
225
+ connectionUri: "mongodb://localhost:27017/example",
226
+ aggregatesCollection: "aggregates-collection",
227
+ eventsCollection: "events-collection",
228
+ runParallelSubscriptions:true
229
+ })
230
+ ]
231
+ })
232
+ export class AppModule {}
233
+ ```
234
+
235
+
236
+
237
+ ## License
238
+ Event Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
10
239
 
11
- Run `nx test core` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@event-nest/core",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "license": "MIT",
5
5
  "author": "Nick Tsitlakidis",
6
6
  "description": "Event sourcing module for NestJS. It provides a set of decorators and interfaces to help you build your event sourcing application.",
@@ -12,14 +12,14 @@
12
12
  ],
13
13
  "type": "commonjs",
14
14
  "peerDependencies": {
15
- "@nestjs/common": "^10.0.2",
16
- "@nestjs/core": "^10.0.2",
15
+ "@nestjs/common": "^9.0.0",
16
+ "@nestjs/core": "^9.0.0",
17
+ "reflect-metadata": "0.1.13",
18
+ "rxjs": "^7.2.0",
17
19
  "tslib": "2.5.3"
18
20
  },
19
21
  "dependencies": {
20
- "class-transformer": "^0.5.1",
21
- "reflect-metadata": "^0.1.13",
22
- "rxjs": "^7.8.0"
22
+ "class-transformer": "^0.5.1"
23
23
  },
24
24
  "main": "./src/index.js",
25
25
  "types": "./src/index.d.ts"
@@ -31,6 +31,7 @@ class AggregateRoot {
31
31
  * If a publisher is not connected, the method will return a rejected promise.
32
32
  * @param events The events to be published
33
33
  */
34
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
35
  publish(events) {
35
36
  this.logger.error("There is no event publisher assigned");
36
37
  return Promise.reject("There is no event publisher assigned");
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate-root.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/aggregate-root.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAExC,yDAAiE;AACjE,uDAA4D;AAC5D,kFAA6E;AAC7E,mDAA2C;AAC3C,4FAAuF;AAQvF,MAAsB,aAAa;IAK/B,YAAuC,GAAW,EAAE,MAAe;QAA5B,QAAG,GAAH,GAAG,CAAQ;QAC9C,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,IAAA,kBAAK,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,eAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3E,CAAC;IAED,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,MAA8C;QAClD,IAAI,CAAC,MAAM,CAAC,KAAK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C,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC;IAC7D,CAAC;IAES,UAAU,CAAC,MAA0B;QAC3C,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,oBAAoB,GAAG,EAAE,CAAC,oBAAoB,CAAC,CAAC;IACtF,CAAC;IAEO,WAAW,CAAC,MAA0B;QAC1C,MAAM,KAAK,GAAsB,EAAE,CAAC;QACpC,MAAM,YAAY,GAAkB,EAAE,CAAC;QACvC,MAAM,gBAAgB,GAAkB,EAAE,CAAC;QAE3C,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YAClB,MAAM,UAAU,GAAG,IAAA,gCAAa,EAAC,EAAE,CAAC,SAAS,CAAC,CAAC;YAC/C,IAAI,IAAA,kBAAK,EAAC,UAAU,CAAC,EAAE;gBACnB,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;aACnC;iBAAM;gBACH,MAAM,YAAY,GAAG,IAAA,yCAAuB,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;gBAC/D,IAAI,IAAA,kBAAK,EAAC,YAAY,CAAC,EAAE;oBACrB,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;iBACvC;qBAAM;oBACH,KAAK,CAAC,IAAI,CAAC;wBACP,YAAY;wBACZ,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC;qBACvC,CAAC,CAAC;iBACN;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,YAAY,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC;CACJ;AA1ID,sCA0IC"}
@@ -28,7 +28,7 @@ class DomainEventEmitter {
28
28
  this._handlers.set(eventId, []);
29
29
  }
30
30
  this._logger.debug(`Binding ${provider.instance?.constructor.name} to event ${eventId}`);
31
- this._handlers.get(eventId).push(provider.instance);
31
+ this._handlers.get(eventId)?.push(provider.instance);
32
32
  });
33
33
  }
34
34
  });
@@ -1 +1 @@
1
- {"version":3,"file":"domain-event-emitter.js","sourceRoot":"","sources":["../../../../../libs/core/src/lib/domain-event-emitter.ts"],"names":[],"mappings":";;;AACA,2EAIqC;AAErC,mDAA2C;AAC3C,2CAAyD;AAEzD,+BAAiE;AAEjE,MAAa,kBAAkB;IAI3B,YAAoB,4BAAqC,KAAK;QAA1C,8BAAyB,GAAzB,yBAAyB,CAAiB;QAC1D,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAwC,CAAC;QACjE,IAAI,CAAC,OAAO,GAAG,IAAI,eAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,eAAe;QACX,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAED,iBAAiB,CAAC,eAAoC;QAClD,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAC/B,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBAClC,IAAI,CAAC,QAAQ,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE;oBACtD,OAAO;iBACV;gBAED,IAAI,IAAA,qDAAyB,EAAC,QAAQ,CAAC,QAAkB,CAAC,EAAE;oBACxD,MAAM,MAAM,GAAG,IAAA,gEAAoC,EAAC,QAAQ,CAAC,QAAkC,CAAC,CAAC;oBACjG,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;wBACrB,MAAM,OAAO,GAAG,IAAA,sCAAU,EAAC,KAAK,CAAW,CAAC;wBAC5C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;4BAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;yBACnC;wBAED,IAAI,CAAC,OAAO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