@nestjs/cqrs 10.2.3 → 10.2.4

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.
@@ -58,7 +58,21 @@ export declare abstract class AggregateRoot<EventBase extends IEvent = IEvent> {
58
58
  * @param event The event to apply.
59
59
  * @param isFromHistory Whether the event is from history.
60
60
  */
61
- apply<T extends EventBase = EventBase>(event: T, isFromHistory?: boolean): void;
61
+ apply<T extends EventBase = EventBase>(event: T, isFromHistory: boolean): void;
62
+ /**
63
+ * Applies an event.
64
+ * If auto commit is enabled, the event will be published immediately (note: must be merged with the publisher context in order to work).
65
+ * Otherwise, the event will be stored in the internal events array, and will be published when the commit method is called.
66
+ * Also, the corresponding event handler will be called (if exists).
67
+ * For example, if the event is called UserCreatedEvent, the "onUserCreatedEvent" method will be called.
68
+ *
69
+ * @param event The event to apply.
70
+ * @param options The options.
71
+ */
72
+ apply<T extends EventBase = EventBase>(event: T, options: {
73
+ fromHistory?: boolean;
74
+ skipHandler?: boolean;
75
+ }): void;
62
76
  protected getEventHandler<T extends EventBase = EventBase>(event: T): Type<IEventHandler> | undefined;
63
77
  protected getEventName(event: any): string;
64
78
  }
@@ -65,23 +65,21 @@ class AggregateRoot {
65
65
  loadFromHistory(history) {
66
66
  history.forEach((event) => this.apply(event, true));
67
67
  }
68
- /**
69
- * Applies an event.
70
- * If auto commit is enabled, the event will be published immediately (note: must be merged with the publisher context in order to work).
71
- * Otherwise, the event will be stored in the internal events array, and will be published when the commit method is called.
72
- * Also, the corresponding event handler will be called (if exists).
73
- * For example, if the event is called UserCreatedEvent, the "onUserCreatedEvent" method will be called.
74
- *
75
- * @param event The event to apply.
76
- * @param isFromHistory Whether the event is from history.
77
- */
78
- apply(event, isFromHistory = false) {
68
+ apply(event, optionsOrIsFromHistory = {}) {
69
+ const isFromHistory = (typeof optionsOrIsFromHistory === 'boolean'
70
+ ? optionsOrIsFromHistory
71
+ : optionsOrIsFromHistory.fromHistory) ?? false;
72
+ const skipHandler = typeof optionsOrIsFromHistory === 'boolean'
73
+ ? false
74
+ : optionsOrIsFromHistory.skipHandler;
79
75
  if (!isFromHistory && !this.autoCommit) {
80
76
  this[INTERNAL_EVENTS].push(event);
81
77
  }
82
78
  this.autoCommit && this.publish(event);
83
- const handler = this.getEventHandler(event);
84
- handler && handler.call(this, event);
79
+ if (!skipHandler) {
80
+ const handler = this.getEventHandler(event);
81
+ handler && handler.call(this, event);
82
+ }
85
83
  }
86
84
  getEventHandler(event) {
87
85
  const handler = `on${this.getEventName(event)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/cqrs",
3
- "version": "10.2.3",
3
+ "version": "10.2.4",
4
4
  "description": "A lightweight CQRS module for Nest framework (node.js)",
5
5
  "license": "MIT",
6
6
  "url": "https://github.com/nestjs/cqrs#readme",
@@ -25,7 +25,7 @@
25
25
  "@commitlint/config-angular": "17.6.7",
26
26
  "@nestjs/common": "10.1.3",
27
27
  "@nestjs/core": "10.1.3",
28
- "@types/node": "18.17.3",
28
+ "@types/node": "18.17.4",
29
29
  "@types/jest": "29.5.3",
30
30
  "@typescript-eslint/eslint-plugin": "6.3.0",
31
31
  "@typescript-eslint/parser": "6.3.0",