@nestjs/cqrs 11.0.0-next.1 → 11.0.0-next.2

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/.husky/commit-msg CHANGED
@@ -1,4 +1 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
1
  npx --no-install commitlint --edit $1
package/.husky/pre-commit CHANGED
@@ -1,4 +1 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
1
  npx --no-install lint-staged
package/dist/event-bus.js CHANGED
@@ -158,16 +158,18 @@ let EventBus = EventBus_1 = class EventBus extends utils_1.ObservableBus {
158
158
  const typeRef = handler.metatype;
159
159
  const events = this.reflectEvents(typeRef);
160
160
  events.forEach((event) => {
161
- const { constructor } = Object.getPrototypeOf(event);
162
- if (!constructor) {
163
- return;
164
- }
165
- const eventId = this.eventIdProvider.getEventId(constructor);
161
+ const eventId = this.eventIdProvider.getEventId(event);
166
162
  this.bind(handler, eventId);
167
163
  });
168
164
  }
169
165
  ofEventId(id) {
170
- return this.subject$.pipe((0, operators_1.filter)((event) => this.eventIdProvider.getEventId(event) === id));
166
+ return this.subject$.pipe((0, operators_1.filter)((event) => {
167
+ const { constructor } = Object.getPrototypeOf(event);
168
+ if (!constructor) {
169
+ return false;
170
+ }
171
+ return this.eventIdProvider.getEventId(constructor) === id;
172
+ }));
171
173
  }
172
174
  registerSaga(saga) {
173
175
  if (typeof saga !== 'function') {
@@ -1,6 +1,7 @@
1
+ import { Type } from '@nestjs/common';
1
2
  import { EventIdProvider, IEvent } from '../interfaces';
2
3
  declare class DefaultEventIdProvider<EventBase extends IEvent = IEvent> implements EventIdProvider<EventBase> {
3
- getEventId(event: EventBase): string | null;
4
+ getEventId(event: Type<EventBase>): string | null;
4
5
  }
5
6
  export declare const defaultEventIdProvider: DefaultEventIdProvider<IEvent>;
6
7
  export {};
@@ -1,11 +1,12 @@
1
+ import { Type } from '@nestjs/common';
1
2
  import { IEvent } from './event.interface';
2
3
  export interface EventIdProvider<EventBase extends IEvent = IEvent> {
3
4
  /**
4
5
  * Retrieves the unique identifier for the given event instance.
5
6
  * Returns null if the event is not associated with any handler.
6
7
  *
7
- * @param event - The event instance for which to retrieve the ID.
8
+ * @param event - The event type for which to retrieve the ID.
8
9
  * @returns The unique identifier for the event, or null if not connected to any handler.
9
10
  */
10
- getEventId(event: EventBase): string | null;
11
+ getEventId(event: Type<EventBase>): string | null;
11
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/cqrs",
3
- "version": "11.0.0-next.1",
3
+ "version": "11.0.0-next.2",
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",
@@ -13,6 +13,7 @@ import { HeroKilledDragonEvent } from '../src/heroes/events/impl/hero-killed-dra
13
13
  import { GetHeroesQuery } from '../src/heroes/queries/impl';
14
14
  import { HERO_ID } from '../src/heroes/repository/fixtures/user';
15
15
  import { ANCIENT_ITEM_ID } from '../src/heroes/sagas/heroes.sagas';
16
+ import { NoopHandler } from '../src/noop/events/handlers/noop.handler';
16
17
  import { waitImmediate } from '../utils/wait-immediate';
17
18
 
18
19
  describe('Basic flows', () => {
@@ -29,14 +30,17 @@ describe('Basic flows', () => {
29
30
  describe('when "KillDragonCommand" command is dispatched', () => {
30
31
  let killDragonExecuteSpy: jest.SpyInstance;
31
32
  let heroKilledDragonHandleSpy: jest.SpyInstance;
33
+ let noopEventHandleSpy: jest.SpyInstance;
32
34
  let command: KillDragonCommand;
33
35
 
34
36
  beforeAll(async () => {
35
37
  const killDragonHandler = moduleRef.get(KillDragonHandler);
36
38
  const heroKilledDragonHandler = moduleRef.get(HeroKilledDragonHandler);
39
+ const noopHandler = moduleRef.get(NoopHandler);
37
40
 
38
41
  killDragonExecuteSpy = jest.spyOn(killDragonHandler, 'execute');
39
42
  heroKilledDragonHandleSpy = jest.spyOn(heroKilledDragonHandler, 'handle');
43
+ noopEventHandleSpy = jest.spyOn(noopHandler, 'handle');
40
44
 
41
45
  const commandBus = moduleRef.get(CommandBus);
42
46
  const heroId = HERO_ID;
@@ -56,6 +60,10 @@ describe('Basic flows', () => {
56
60
  expect(heroKilledDragonHandleSpy).toHaveBeenCalledWith(event);
57
61
  });
58
62
 
63
+ it('should not trigger "NoopHandler" event', () => {
64
+ expect(noopEventHandleSpy).not.toHaveBeenCalled();
65
+ });
66
+
59
67
  describe('when saga triggered', () => {
60
68
  let dropAncientExecuteSpy: jest.SpyInstance;
61
69
  let heroFoundItemSpy: jest.SpyInstance;