@nestjs/cqrs 7.0.0 → 8.0.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.
Files changed (47) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.github/ISSUE_TEMPLATE/Bug_report.yml +106 -0
  3. package/.github/ISSUE_TEMPLATE/Feature_request.yml +52 -0
  4. package/.github/ISSUE_TEMPLATE/Regression.yml +78 -0
  5. package/.github/ISSUE_TEMPLATE/config.yml +7 -0
  6. package/.github/PULL_REQUEST_TEMPLATE.md +10 -14
  7. package/CONTRIBUTING.md +4 -3
  8. package/LICENSE +21 -0
  9. package/dist/aggregate-root.d.ts +4 -2
  10. package/dist/aggregate-root.js +2 -1
  11. package/dist/command-bus.d.ts +4 -4
  12. package/dist/command-bus.js +56 -53
  13. package/dist/cqrs.module.js +25 -28
  14. package/dist/decorators/command-handler.decorator.d.ts +10 -0
  15. package/dist/decorators/command-handler.decorator.js +16 -1
  16. package/dist/decorators/constants.d.ts +4 -1
  17. package/dist/decorators/constants.js +5 -2
  18. package/dist/decorators/events-handler.decorator.d.ts +10 -0
  19. package/dist/decorators/events-handler.decorator.js +18 -1
  20. package/dist/decorators/index.js +2 -2
  21. package/dist/decorators/query-handler.decorator.d.ts +10 -0
  22. package/dist/decorators/query-handler.decorator.js +16 -1
  23. package/dist/decorators/saga.decorator.d.ts +5 -0
  24. package/dist/decorators/saga.decorator.js +7 -1
  25. package/dist/event-bus.d.ts +4 -4
  26. package/dist/event-bus.js +78 -81
  27. package/dist/event-publisher.js +29 -26
  28. package/dist/exceptions/index.js +2 -2
  29. package/dist/helpers/default-get-event-id.d.ts +4 -0
  30. package/dist/helpers/default-get-event-id.js +13 -0
  31. package/dist/helpers/default-get-event-name.js +2 -1
  32. package/dist/index.js +8 -2
  33. package/dist/interfaces/commands/command-bus.interface.d.ts +1 -1
  34. package/dist/interfaces/commands/command-metadata.interface.d.ts +3 -0
  35. package/dist/interfaces/commands/command-metadata.interface.js +2 -0
  36. package/dist/interfaces/index.js +2 -2
  37. package/dist/interfaces/queries/query-metadata.interface.d.ts +3 -0
  38. package/dist/interfaces/queries/query-metadata.interface.js +2 -0
  39. package/dist/operators/index.js +2 -2
  40. package/dist/operators/of-type.d.ts +8 -0
  41. package/dist/operators/of-type.js +9 -1
  42. package/dist/query-bus.d.ts +3 -3
  43. package/dist/query-bus.js +59 -56
  44. package/dist/services/explorer.service.js +35 -38
  45. package/dist/utils/index.js +2 -2
  46. package/package.json +26 -23
  47. package/.github/ISSUE_TEMPLATE.md +0 -46
package/dist/query-bus.js CHANGED
@@ -27,64 +27,67 @@ const exceptions_1 = require("./exceptions");
27
27
  const invalid_query_handler_exception_1 = require("./exceptions/invalid-query-handler.exception");
28
28
  const default_query_pubsub_1 = require("./helpers/default-query-pubsub");
29
29
  const observable_bus_1 = require("./utils/observable-bus");
30
- let QueryBus = (() => {
31
- let QueryBus = class QueryBus extends observable_bus_1.ObservableBus {
32
- constructor(moduleRef) {
33
- super();
34
- this.moduleRef = moduleRef;
35
- this.handlers = new Map();
36
- this.useDefaultPublisher();
37
- }
38
- get publisher() {
39
- return this._publisher;
40
- }
41
- set publisher(_publisher) {
42
- this._publisher = _publisher;
43
- }
44
- execute(query) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const queryName = this.getQueryName(query);
47
- const handler = this.handlers.get(queryName);
48
- if (!handler) {
49
- throw new exceptions_1.QueryHandlerNotFoundException(queryName);
50
- }
51
- this.subject$.next(query);
52
- const result = yield handler.execute(query);
53
- return result;
54
- });
55
- }
56
- bind(handler, name) {
57
- this.handlers.set(name, handler);
58
- }
59
- register(handlers = []) {
60
- handlers.forEach((handler) => this.registerHandler(handler));
61
- }
62
- registerHandler(handler) {
63
- const instance = this.moduleRef.get(handler, { strict: false });
64
- if (!instance) {
65
- return;
66
- }
67
- const target = this.reflectQueryName(handler);
68
- if (!target) {
69
- throw new invalid_query_handler_exception_1.InvalidQueryHandlerException();
30
+ let QueryBus = class QueryBus extends observable_bus_1.ObservableBus {
31
+ constructor(moduleRef) {
32
+ super();
33
+ this.moduleRef = moduleRef;
34
+ this.handlers = new Map();
35
+ this.useDefaultPublisher();
36
+ }
37
+ get publisher() {
38
+ return this._publisher;
39
+ }
40
+ set publisher(_publisher) {
41
+ this._publisher = _publisher;
42
+ }
43
+ execute(query) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const queryId = this.getQueryId(query);
46
+ const handler = this.handlers.get(queryId);
47
+ if (!handler) {
48
+ throw new exceptions_1.QueryHandlerNotFoundException(queryId);
70
49
  }
71
- this.bind(instance, target.name);
50
+ this.subject$.next(query);
51
+ const result = yield handler.execute(query);
52
+ return result;
53
+ });
54
+ }
55
+ bind(handler, queryId) {
56
+ this.handlers.set(queryId, handler);
57
+ }
58
+ register(handlers = []) {
59
+ handlers.forEach((handler) => this.registerHandler(handler));
60
+ }
61
+ registerHandler(handler) {
62
+ const instance = this.moduleRef.get(handler, { strict: false });
63
+ if (!instance) {
64
+ return;
72
65
  }
73
- getQueryName(query) {
74
- const { constructor } = Object.getPrototypeOf(query);
75
- return constructor.name;
66
+ const target = this.reflectQueryId(handler);
67
+ if (!target) {
68
+ throw new invalid_query_handler_exception_1.InvalidQueryHandlerException();
76
69
  }
77
- reflectQueryName(handler) {
78
- return Reflect.getMetadata(constants_1.QUERY_HANDLER_METADATA, handler);
70
+ this.bind(instance, target);
71
+ }
72
+ getQueryId(query) {
73
+ const { constructor: queryType } = Object.getPrototypeOf(query);
74
+ const queryMetadata = Reflect.getMetadata(constants_1.QUERY_METADATA, queryType);
75
+ if (!queryMetadata) {
76
+ throw new exceptions_1.QueryHandlerNotFoundException(queryType.name);
79
77
  }
80
- useDefaultPublisher() {
81
- this._publisher = new default_query_pubsub_1.DefaultQueryPubSub(this.subject$);
82
- }
83
- };
84
- QueryBus = __decorate([
85
- common_1.Injectable(),
86
- __metadata("design:paramtypes", [core_1.ModuleRef])
87
- ], QueryBus);
88
- return QueryBus;
89
- })();
78
+ return queryMetadata.id;
79
+ }
80
+ reflectQueryId(handler) {
81
+ const query = Reflect.getMetadata(constants_1.QUERY_HANDLER_METADATA, handler);
82
+ const queryMetadata = Reflect.getMetadata(constants_1.QUERY_METADATA, query);
83
+ return queryMetadata.id;
84
+ }
85
+ useDefaultPublisher() {
86
+ this._publisher = new default_query_pubsub_1.DefaultQueryPubSub(this.subject$);
87
+ }
88
+ };
89
+ QueryBus = __decorate([
90
+ (0, common_1.Injectable)(),
91
+ __metadata("design:paramtypes", [core_1.ModuleRef])
92
+ ], QueryBus);
90
93
  exports.QueryBus = QueryBus;
@@ -13,44 +13,41 @@ exports.ExplorerService = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const modules_container_1 = require("@nestjs/core/injector/modules-container");
15
15
  const constants_1 = require("../decorators/constants");
16
- let ExplorerService = (() => {
17
- let ExplorerService = class ExplorerService {
18
- constructor(modulesContainer) {
19
- this.modulesContainer = modulesContainer;
16
+ let ExplorerService = class ExplorerService {
17
+ constructor(modulesContainer) {
18
+ this.modulesContainer = modulesContainer;
19
+ }
20
+ explore() {
21
+ const modules = [...this.modulesContainer.values()];
22
+ const commands = this.flatMap(modules, (instance) => this.filterProvider(instance, constants_1.COMMAND_HANDLER_METADATA));
23
+ const queries = this.flatMap(modules, (instance) => this.filterProvider(instance, constants_1.QUERY_HANDLER_METADATA));
24
+ const events = this.flatMap(modules, (instance) => this.filterProvider(instance, constants_1.EVENTS_HANDLER_METADATA));
25
+ const sagas = this.flatMap(modules, (instance) => this.filterProvider(instance, constants_1.SAGA_METADATA));
26
+ return { commands, queries, events, sagas };
27
+ }
28
+ flatMap(modules, callback) {
29
+ const items = modules
30
+ .map((module) => [...module.providers.values()].map(callback))
31
+ .reduce((a, b) => a.concat(b), []);
32
+ return items.filter((element) => !!element);
33
+ }
34
+ filterProvider(wrapper, metadataKey) {
35
+ const { instance } = wrapper;
36
+ if (!instance) {
37
+ return undefined;
20
38
  }
21
- explore() {
22
- const modules = [...this.modulesContainer.values()];
23
- const commands = this.flatMap(modules, (instance) => this.filterProvider(instance, constants_1.COMMAND_HANDLER_METADATA));
24
- const queries = this.flatMap(modules, (instance) => this.filterProvider(instance, constants_1.QUERY_HANDLER_METADATA));
25
- const events = this.flatMap(modules, (instance) => this.filterProvider(instance, constants_1.EVENTS_HANDLER_METADATA));
26
- const sagas = this.flatMap(modules, (instance) => this.filterProvider(instance, constants_1.SAGA_METADATA));
27
- return { commands, queries, events, sagas };
39
+ return this.extractMetadata(instance, metadataKey);
40
+ }
41
+ extractMetadata(instance, metadataKey) {
42
+ if (!instance.constructor) {
43
+ return;
28
44
  }
29
- flatMap(modules, callback) {
30
- const items = modules
31
- .map((module) => [...module.providers.values()].map(callback))
32
- .reduce((a, b) => a.concat(b), []);
33
- return items.filter((element) => !!element);
34
- }
35
- filterProvider(wrapper, metadataKey) {
36
- const { instance } = wrapper;
37
- if (!instance) {
38
- return undefined;
39
- }
40
- return this.extractMetadata(instance, metadataKey);
41
- }
42
- extractMetadata(instance, metadataKey) {
43
- if (!instance.constructor) {
44
- return;
45
- }
46
- const metadata = Reflect.getMetadata(metadataKey, instance.constructor);
47
- return metadata ? instance.constructor : undefined;
48
- }
49
- };
50
- ExplorerService = __decorate([
51
- common_1.Injectable(),
52
- __metadata("design:paramtypes", [modules_container_1.ModulesContainer])
53
- ], ExplorerService);
54
- return ExplorerService;
55
- })();
45
+ const metadata = Reflect.getMetadata(metadataKey, instance.constructor);
46
+ return metadata ? instance.constructor : undefined;
47
+ }
48
+ };
49
+ ExplorerService = __decorate([
50
+ (0, common_1.Injectable)(),
51
+ __metadata("design:paramtypes", [modules_container_1.ModulesContainer])
52
+ ], ExplorerService);
56
53
  exports.ExplorerService = ExplorerService;
@@ -7,7 +7,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
7
7
  o[k2] = m[k];
8
8
  }));
9
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
- }
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./observable-bus"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/cqrs",
3
- "version": "7.0.0",
3
+ "version": "8.0.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",
@@ -16,33 +16,36 @@
16
16
  "prerelease": "npm run build",
17
17
  "release": "release-it"
18
18
  },
19
+ "dependencies": {
20
+ "uuid": "8.3.2"
21
+ },
19
22
  "devDependencies": {
20
- "@commitlint/cli": "8.3.5",
21
- "@commitlint/config-angular": "8.3.4",
22
- "@nestjs/common": "7.0.11",
23
- "@nestjs/core": "7.0.11",
24
- "@types/node": "11.15.2",
25
- "@types/jest": "25.2.2",
26
- "@typescript-eslint/eslint-plugin": "2.33.0",
27
- "@typescript-eslint/parser": "2.33.0",
28
- "eslint": "7.0.0",
29
- "eslint-config-prettier": "6.11.0",
30
- "eslint-plugin-import": "2.20.2",
31
- "husky": "4.2.5",
32
- "jest": "26.0.1",
33
- "lint-staged": "10.2.2",
34
- "prettier": "2.0.5",
23
+ "@commitlint/cli": "16.2.1",
24
+ "@commitlint/config-angular": "16.2.1",
25
+ "@nestjs/common": "8.3.0",
26
+ "@nestjs/core": "8.3.0",
27
+ "@types/node": "16.11.24",
28
+ "@types/jest": "27.4.0",
29
+ "@typescript-eslint/eslint-plugin": "5.11.0",
30
+ "@typescript-eslint/parser": "5.11.0",
31
+ "eslint": "8.9.0",
32
+ "eslint-config-prettier": "8.3.0",
33
+ "eslint-plugin-import": "2.25.4",
34
+ "husky": "7.0.4",
35
+ "jest": "27.5.1",
36
+ "lint-staged": "12.3.4",
37
+ "prettier": "2.5.1",
35
38
  "reflect-metadata": "0.1.13",
36
- "release-it": "13.5.8",
37
- "rxjs": "6.5.5",
38
- "ts-jest": "25.5.1",
39
- "typescript": "3.9.2"
39
+ "release-it": "14.12.4",
40
+ "rxjs": "7.5.4",
41
+ "ts-jest": "27.1.3",
42
+ "typescript": "4.5.5"
40
43
  },
41
44
  "peerDependencies": {
42
- "@nestjs/common": "^6.0.0 || ^7.0.0",
43
- "@nestjs/core": "^6.0.0 || ^7.0.0",
45
+ "@nestjs/common": "^8.0.0",
46
+ "@nestjs/core": "^8.0.0",
44
47
  "reflect-metadata": "0.1.13",
45
- "rxjs": "^6.4.0"
48
+ "rxjs": "^7.2.0"
46
49
  },
47
50
  "lint-staged": {
48
51
  "*.ts": [
@@ -1,46 +0,0 @@
1
- <!--
2
- PLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.
3
-
4
- ISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION.
5
- -->
6
-
7
- ## I'm submitting a...
8
- <!--
9
- Please search GitHub for a similar issue or PR before submitting.
10
- Check one of the following options with "x" -->
11
- <pre><code>
12
- [ ] Regression <!--(a behavior that used to work and stopped working in a new release)-->
13
- [ ] Bug report
14
- [ ] Feature request
15
- [ ] Documentation issue or request
16
- [ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
17
- </code></pre>
18
-
19
- ## Current behavior
20
- <!-- Describe how the issue manifests. -->
21
-
22
-
23
- ## Expected behavior
24
- <!-- Describe what the desired behavior would be. -->
25
-
26
-
27
- ## Minimal reproduction of the problem with instructions
28
- <!-- Please share a repo, a gist, or step-by-step instructions. -->
29
-
30
- ## What is the motivation / use case for changing the behavior?
31
- <!-- Describe the motivation or the concrete use case. -->
32
-
33
-
34
- ## Environment
35
-
36
- <pre><code>
37
- Nest version: X.Y.Z
38
- <!-- Check whether this is still an issue in the most recent Nest version -->
39
-
40
- For Tooling issues:
41
- - Node version: XX <!-- run `node --version` -->
42
- - Platform: <!-- Mac, Linux, Windows -->
43
-
44
- Others:
45
- <!-- Anything else relevant? Operating system version, IDE, package manager, ... -->
46
- </code></pre>