@nestjs/cqrs 11.0.0-next.1 → 11.0.0
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/.circleci/config.yml +2 -5
- package/.husky/commit-msg +0 -3
- package/.husky/pre-commit +0 -3
- package/dist/aggregate-root.js +1 -0
- package/dist/event-bus.js +8 -6
- package/dist/helpers/default-event-id-provider.d.ts +2 -1
- package/dist/interfaces/events/event-id-provider.interface.d.ts +3 -2
- package/eslint.config.mjs +42 -0
- package/package.json +21 -20
- package/test/e2e/basic-flows.spec.ts +8 -0
- package/tsconfig.build.json +4 -0
package/.circleci/config.yml
CHANGED
|
@@ -7,7 +7,7 @@ aliases:
|
|
|
7
7
|
- &install-deps
|
|
8
8
|
run:
|
|
9
9
|
name: Install dependencies
|
|
10
|
-
command: npm
|
|
10
|
+
command: npm install --ignore-scripts
|
|
11
11
|
- &build-packages
|
|
12
12
|
run:
|
|
13
13
|
name: Build
|
|
@@ -20,14 +20,11 @@ jobs:
|
|
|
20
20
|
- image: cimg/node:22.3
|
|
21
21
|
steps:
|
|
22
22
|
- checkout
|
|
23
|
-
- run:
|
|
24
|
-
name: Update NPM version
|
|
25
|
-
command: sudo npm install -g npm@latest
|
|
26
23
|
- restore_cache:
|
|
27
24
|
key: dependency-cache-{{ checksum "package.json" }}
|
|
28
25
|
- run:
|
|
29
26
|
name: Install dependencies
|
|
30
|
-
command: npm
|
|
27
|
+
command: npm install --ignore-scripts
|
|
31
28
|
- save_cache:
|
|
32
29
|
key: dependency-cache-{{ checksum "package.json" }}
|
|
33
30
|
paths:
|
package/.husky/commit-msg
CHANGED
package/.husky/pre-commit
CHANGED
package/dist/aggregate-root.js
CHANGED
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
|
|
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) =>
|
|
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
|
|
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
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import eslint from '@eslint/js';
|
|
3
|
+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
|
4
|
+
import globals from 'globals';
|
|
5
|
+
import tseslint from 'typescript-eslint';
|
|
6
|
+
|
|
7
|
+
export default tseslint.config(
|
|
8
|
+
{
|
|
9
|
+
ignores: ['tests/**'],
|
|
10
|
+
},
|
|
11
|
+
eslint.configs.recommended,
|
|
12
|
+
...tseslint.configs.recommendedTypeChecked,
|
|
13
|
+
eslintPluginPrettierRecommended,
|
|
14
|
+
{
|
|
15
|
+
languageOptions: {
|
|
16
|
+
globals: {
|
|
17
|
+
...globals.node,
|
|
18
|
+
...globals.jest,
|
|
19
|
+
},
|
|
20
|
+
ecmaVersion: 5,
|
|
21
|
+
sourceType: 'module',
|
|
22
|
+
parserOptions: {
|
|
23
|
+
projectService: true,
|
|
24
|
+
tsconfigRootDir: import.meta.dirname,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
rules: {
|
|
30
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
31
|
+
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
32
|
+
'@typescript-eslint/no-unsafe-call': 'off',
|
|
33
|
+
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
34
|
+
'@typescript-eslint/no-unsafe-function-type': 'off',
|
|
35
|
+
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
36
|
+
'@typescript-eslint/no-unsafe-return': 'off',
|
|
37
|
+
'@typescript-eslint/require-await': 'warn',
|
|
38
|
+
'@typescript-eslint/no-unused-expressions': 'warn',
|
|
39
|
+
'@typescript-eslint/no-empty-object-type': 'off',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/cqrs",
|
|
3
|
-
"version": "11.0.0
|
|
3
|
+
"version": "11.0.0",
|
|
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",
|
|
@@ -15,36 +15,37 @@
|
|
|
15
15
|
"publish:npm": "npm publish --access public",
|
|
16
16
|
"prerelease": "npm run build",
|
|
17
17
|
"release": "release-it",
|
|
18
|
-
"prepare": "husky
|
|
18
|
+
"prepare": "husky",
|
|
19
19
|
"test:e2e": "jest --config ./test/jest-e2e.json --runInBand"
|
|
20
20
|
},
|
|
21
|
-
"dependencies": {},
|
|
22
21
|
"devDependencies": {
|
|
23
|
-
"@commitlint/cli": "19.6.
|
|
24
|
-
"@commitlint/config-angular": "19.
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@nestjs/
|
|
22
|
+
"@commitlint/cli": "19.6.1",
|
|
23
|
+
"@commitlint/config-angular": "19.7.0",
|
|
24
|
+
"@eslint/eslintrc": "3.2.0",
|
|
25
|
+
"@eslint/js": "9.18.0",
|
|
26
|
+
"@nestjs/common": "11.0.1",
|
|
27
|
+
"@nestjs/core": "11.0.1",
|
|
28
|
+
"@nestjs/testing": "11.0.1",
|
|
28
29
|
"@types/jest": "29.5.14",
|
|
29
|
-
"@types/node": "22.10.
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"eslint": "
|
|
33
|
-
"
|
|
34
|
-
"eslint-plugin-import": "2.31.0",
|
|
30
|
+
"@types/node": "22.10.7",
|
|
31
|
+
"eslint": "9.18.0",
|
|
32
|
+
"eslint-config-prettier": "10.0.1",
|
|
33
|
+
"eslint-plugin-prettier": "5.2.2",
|
|
34
|
+
"globals": "15.14.0",
|
|
35
35
|
"husky": "9.1.7",
|
|
36
36
|
"jest": "29.7.0",
|
|
37
|
-
"lint-staged": "15.
|
|
38
|
-
"prettier": "3.4.
|
|
37
|
+
"lint-staged": "15.4.1",
|
|
38
|
+
"prettier": "3.4.2",
|
|
39
39
|
"reflect-metadata": "0.2.2",
|
|
40
|
-
"release-it": "
|
|
40
|
+
"release-it": "18.1.1",
|
|
41
41
|
"rxjs": "7.8.1",
|
|
42
42
|
"ts-jest": "29.2.5",
|
|
43
|
-
"typescript": "5.7.
|
|
43
|
+
"typescript": "5.7.3",
|
|
44
|
+
"typescript-eslint": "8.20.0"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"@nestjs/common": "^
|
|
47
|
-
"@nestjs/core": "^
|
|
47
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
48
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
48
49
|
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
49
50
|
"rxjs": "^7.2.0"
|
|
50
51
|
},
|
|
@@ -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;
|