@nestjs/cqrs 8.0.0 → 8.0.1
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 +1 -1
- package/.github/ISSUE_TEMPLATE/Bug_report.yml +106 -0
- package/.github/ISSUE_TEMPLATE/Feature_request.yml +52 -0
- package/.github/ISSUE_TEMPLATE/Regression.yml +78 -0
- package/.github/ISSUE_TEMPLATE/config.yml +7 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +10 -14
- package/dist/aggregate-root.d.ts +3 -2
- package/dist/command-bus.d.ts +3 -3
- package/dist/command-bus.js +19 -13
- package/dist/cqrs.module.js +1 -1
- package/dist/decorators/command-handler.decorator.js +4 -0
- package/dist/decorators/constants.d.ts +3 -1
- package/dist/decorators/constants.js +4 -2
- package/dist/decorators/query-handler.decorator.js +4 -0
- package/dist/event-bus.js +4 -4
- package/dist/event-publisher.js +1 -1
- package/dist/interfaces/commands/command-metadata.interface.d.ts +3 -0
- package/dist/interfaces/commands/command-metadata.interface.js +2 -0
- package/dist/interfaces/queries/query-metadata.interface.d.ts +3 -0
- package/dist/interfaces/queries/query-metadata.interface.js +2 -0
- package/dist/operators/of-type.js +1 -1
- package/dist/query-bus.d.ts +3 -3
- package/dist/query-bus.js +19 -13
- package/dist/services/explorer.service.js +1 -1
- package/package.json +22 -19
- package/.github/ISSUE_TEMPLATE.md +0 -46
package/.circleci/config.yml
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
name: "\U0001F41B Bug Report"
|
|
2
|
+
description: "If something isn't working as expected \U0001F914"
|
|
3
|
+
labels: ["needs triage", "bug"]
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: |
|
|
8
|
+
## :warning: We use GitHub Issues to track bug reports, feature requests and regressions
|
|
9
|
+
|
|
10
|
+
If you are not sure that your issue is a bug, you could:
|
|
11
|
+
|
|
12
|
+
- use our [Discord community](https://discord.gg/NestJS)
|
|
13
|
+
- use [StackOverflow using the tag `nestjs`](https://stackoverflow.com/questions/tagged/nestjs)
|
|
14
|
+
- If it's just a quick question you can ping [our Twitter](https://twitter.com/nestframework)
|
|
15
|
+
|
|
16
|
+
**NOTE:** You don't need to answer questions that you know that aren't relevant.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
- type: checkboxes
|
|
21
|
+
attributes:
|
|
22
|
+
label: "Is there an existing issue for this?"
|
|
23
|
+
description: "Please search [here](./?q=is%3Aissue) to see if an issue already exists for the bug you encountered"
|
|
24
|
+
options:
|
|
25
|
+
- label: "I have searched the existing issues"
|
|
26
|
+
required: true
|
|
27
|
+
|
|
28
|
+
- type: textarea
|
|
29
|
+
validations:
|
|
30
|
+
required: true
|
|
31
|
+
attributes:
|
|
32
|
+
label: "Current behavior"
|
|
33
|
+
description: "How the issue manifests?"
|
|
34
|
+
|
|
35
|
+
- type: input
|
|
36
|
+
validations:
|
|
37
|
+
required: true
|
|
38
|
+
attributes:
|
|
39
|
+
label: "Minimum reproduction code"
|
|
40
|
+
description: "An URL to some git repository or gist that reproduces this issue. [Wtf is a minimum reproduction?](https://jmcdo29.github.io/wtf-is-a-minimum-reproduction)"
|
|
41
|
+
placeholder: "https://github.com/..."
|
|
42
|
+
|
|
43
|
+
- type: textarea
|
|
44
|
+
attributes:
|
|
45
|
+
label: "Steps to reproduce"
|
|
46
|
+
description: |
|
|
47
|
+
How the issue manifests?
|
|
48
|
+
You could leave this blank if you alread write this in your reproduction code/repo
|
|
49
|
+
placeholder: |
|
|
50
|
+
1. `npm i`
|
|
51
|
+
2. `npm start:dev`
|
|
52
|
+
3. See error...
|
|
53
|
+
|
|
54
|
+
- type: textarea
|
|
55
|
+
validations:
|
|
56
|
+
required: true
|
|
57
|
+
attributes:
|
|
58
|
+
label: "Expected behavior"
|
|
59
|
+
description: "A clear and concise description of what you expected to happend (or code)"
|
|
60
|
+
|
|
61
|
+
- type: markdown
|
|
62
|
+
attributes:
|
|
63
|
+
value: |
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
- type: input
|
|
67
|
+
validations:
|
|
68
|
+
required: true
|
|
69
|
+
attributes:
|
|
70
|
+
label: "Package version"
|
|
71
|
+
description: |
|
|
72
|
+
Which version of `@nestjs/cqrs` are you using?
|
|
73
|
+
**Tip**: Make sure that all of yours `@nestjs/*` dependencies are in sync!
|
|
74
|
+
placeholder: "8.1.3"
|
|
75
|
+
|
|
76
|
+
- type: input
|
|
77
|
+
attributes:
|
|
78
|
+
label: "NestJS version"
|
|
79
|
+
description: "Which version of `@nestjs/core` are you using?"
|
|
80
|
+
placeholder: "8.1.3"
|
|
81
|
+
|
|
82
|
+
- type: input
|
|
83
|
+
attributes:
|
|
84
|
+
label: "Node.js version"
|
|
85
|
+
description: "Which version of Node.js are you using?"
|
|
86
|
+
placeholder: "14.17.6"
|
|
87
|
+
|
|
88
|
+
- type: checkboxes
|
|
89
|
+
attributes:
|
|
90
|
+
label: "In which operating systems have you tested?"
|
|
91
|
+
options:
|
|
92
|
+
- label: macOS
|
|
93
|
+
- label: Windows
|
|
94
|
+
- label: Linux
|
|
95
|
+
|
|
96
|
+
- type: markdown
|
|
97
|
+
attributes:
|
|
98
|
+
value: |
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
- type: textarea
|
|
102
|
+
attributes:
|
|
103
|
+
label: "Other"
|
|
104
|
+
description: |
|
|
105
|
+
Anything else relevant? eg: Logs, OS version, IDE, package manager, etc.
|
|
106
|
+
**Tip:** You can attach images, recordings or log files by clicking this area to highlight it and then dragging files in
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: "\U0001F680 Feature Request"
|
|
2
|
+
description: "I have a suggestion \U0001F63B!"
|
|
3
|
+
labels: ["feature"]
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: |
|
|
8
|
+
## :warning: We use GitHub Issues to track bug reports, feature requests and regressions
|
|
9
|
+
|
|
10
|
+
If you are not sure that your issue is a bug, you could:
|
|
11
|
+
|
|
12
|
+
- use our [Discord community](https://discord.gg/NestJS)
|
|
13
|
+
- use [StackOverflow using the tag `nestjs`](https://stackoverflow.com/questions/tagged/nestjs)
|
|
14
|
+
- If it's just a quick question you can ping [our Twitter](https://twitter.com/nestframework)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
- type: checkboxes
|
|
19
|
+
attributes:
|
|
20
|
+
label: "Is there an existing issue that is already proposing this?"
|
|
21
|
+
description: "Please search [here](./?q=is%3Aissue) to see if an issue already exists for the feature you are requesting"
|
|
22
|
+
options:
|
|
23
|
+
- label: "I have searched the existing issues"
|
|
24
|
+
required: true
|
|
25
|
+
|
|
26
|
+
- type: textarea
|
|
27
|
+
validations:
|
|
28
|
+
required: true
|
|
29
|
+
attributes:
|
|
30
|
+
label: "Is your feature request related to a problem? Please describe it"
|
|
31
|
+
description: "A clear and concise description of what the problem is"
|
|
32
|
+
placeholder: |
|
|
33
|
+
I have an issue when ...
|
|
34
|
+
|
|
35
|
+
- type: textarea
|
|
36
|
+
validations:
|
|
37
|
+
required: true
|
|
38
|
+
attributes:
|
|
39
|
+
label: "Describe the solution you'd like"
|
|
40
|
+
description: "A clear and concise description of what you want to happen. Add any considered drawbacks"
|
|
41
|
+
|
|
42
|
+
- type: textarea
|
|
43
|
+
attributes:
|
|
44
|
+
label: "Teachability, documentation, adoption, migration strategy"
|
|
45
|
+
description: "If you can, explain how users will be able to use this and possibly write out a version the docs. Maybe a screenshot or design?"
|
|
46
|
+
|
|
47
|
+
- type: textarea
|
|
48
|
+
validations:
|
|
49
|
+
required: true
|
|
50
|
+
attributes:
|
|
51
|
+
label: "What is the motivation / use case for changing the behavior?"
|
|
52
|
+
description: "Describe the motivation or the concrete use case"
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: "\U0001F4A5 Regression"
|
|
2
|
+
description: "Report an unexpected behavior while upgrading your Nest application!"
|
|
3
|
+
labels: ["needs triage"]
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: |
|
|
8
|
+
## :warning: We use GitHub Issues to track bug reports, feature requests and regressions
|
|
9
|
+
|
|
10
|
+
If you are not sure that your issue is a bug, you could:
|
|
11
|
+
|
|
12
|
+
- use our [Discord community](https://discord.gg/NestJS)
|
|
13
|
+
- use [StackOverflow using the tag `nestjs`](https://stackoverflow.com/questions/tagged/nestjs)
|
|
14
|
+
- If it's just a quick question you can ping [our Twitter](https://twitter.com/nestframework)
|
|
15
|
+
|
|
16
|
+
**NOTE:** You don't need to answer questions that you know that aren't relevant.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
- type: checkboxes
|
|
21
|
+
attributes:
|
|
22
|
+
label: "Did you read the migration guide?"
|
|
23
|
+
description: "Check out the [migration guide here](https://docs.nestjs.com/migration-guide)!"
|
|
24
|
+
options:
|
|
25
|
+
- label: "I have read the whole migration guide"
|
|
26
|
+
required: false
|
|
27
|
+
|
|
28
|
+
- type: checkboxes
|
|
29
|
+
attributes:
|
|
30
|
+
label: "Is there an existing issue that is already proposing this?"
|
|
31
|
+
description: "Please search [here](./?q=is%3Aissue) to see if an issue already exists for the feature you are requesting"
|
|
32
|
+
options:
|
|
33
|
+
- label: "I have searched the existing issues"
|
|
34
|
+
required: true
|
|
35
|
+
|
|
36
|
+
- type: input
|
|
37
|
+
attributes:
|
|
38
|
+
label: "Potential Commit/PR that introduced the regression"
|
|
39
|
+
description: "If you have time to investigate, what PR/date/version introduced this issue"
|
|
40
|
+
placeholder: "PR #123 or commit 5b3c4a4"
|
|
41
|
+
|
|
42
|
+
- type: input
|
|
43
|
+
attributes:
|
|
44
|
+
label: "Versions"
|
|
45
|
+
description: "From which version of `@nestjs/cqrs` to which version you are upgrading"
|
|
46
|
+
placeholder: "8.1.0 -> 8.1.3"
|
|
47
|
+
|
|
48
|
+
- type: textarea
|
|
49
|
+
validations:
|
|
50
|
+
required: true
|
|
51
|
+
attributes:
|
|
52
|
+
label: "Describe the regression"
|
|
53
|
+
description: "A clear and concise description of what the regression is"
|
|
54
|
+
|
|
55
|
+
- type: textarea
|
|
56
|
+
attributes:
|
|
57
|
+
label: "Minimum reproduction code"
|
|
58
|
+
description: |
|
|
59
|
+
Please share a git repo, a gist, or step-by-step instructions. [Wtf is a minimum reproduction?](https://jmcdo29.github.io/wtf-is-a-minimum-reproduction)
|
|
60
|
+
**Tip:** If you leave a minimum repository, we will understand your issue faster!
|
|
61
|
+
value: |
|
|
62
|
+
```ts
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- type: textarea
|
|
67
|
+
validations:
|
|
68
|
+
required: true
|
|
69
|
+
attributes:
|
|
70
|
+
label: "Expected behavior"
|
|
71
|
+
description: "A clear and concise description of what you expected to happend (or code)"
|
|
72
|
+
|
|
73
|
+
- type: textarea
|
|
74
|
+
attributes:
|
|
75
|
+
label: "Other"
|
|
76
|
+
description: |
|
|
77
|
+
Anything else relevant? eg: Logs, OS version, IDE, package manager, etc.
|
|
78
|
+
**Tip:** You can attach images, recordings or log files by clicking this area to highlight it and then dragging files in
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
## To encourage contributors to use issue templates, we don't allow blank issues
|
|
2
|
+
blank_issues_enabled: false
|
|
3
|
+
|
|
4
|
+
contact_links:
|
|
5
|
+
- name: "\u2753 Discord Community of NestJS"
|
|
6
|
+
url: "https://discord.gg/NestJS"
|
|
7
|
+
about: "Please ask support questions or discuss suggestions/enhancements here."
|
|
@@ -10,15 +10,13 @@ Please check if your PR fulfills the following requirements:
|
|
|
10
10
|
What kind of change does this PR introduce?
|
|
11
11
|
|
|
12
12
|
<!-- Please check the one that applies to this PR using "x". -->
|
|
13
|
-
|
|
14
|
-
[ ]
|
|
15
|
-
[ ]
|
|
16
|
-
[ ]
|
|
17
|
-
[ ]
|
|
18
|
-
[ ]
|
|
19
|
-
[ ]
|
|
20
|
-
[ ] Other... Please describe:
|
|
21
|
-
```
|
|
13
|
+
- [ ] Bugfix
|
|
14
|
+
- [ ] Feature
|
|
15
|
+
- [ ] Code style update (formatting, local variables)
|
|
16
|
+
- [ ] Refactoring (no functional changes, no api changes)
|
|
17
|
+
- [ ] Build related changes
|
|
18
|
+
- [ ] CI related changes
|
|
19
|
+
- [ ] Other... Please describe:
|
|
22
20
|
|
|
23
21
|
## What is the current behavior?
|
|
24
22
|
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
|
|
@@ -30,12 +28,10 @@ Issue Number: N/A
|
|
|
30
28
|
|
|
31
29
|
|
|
32
30
|
## Does this PR introduce a breaking change?
|
|
33
|
-
|
|
34
|
-
[ ]
|
|
35
|
-
[ ] No
|
|
36
|
-
```
|
|
31
|
+
- [ ] Yes
|
|
32
|
+
- [ ] No
|
|
37
33
|
|
|
38
34
|
<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. -->
|
|
39
35
|
|
|
40
36
|
|
|
41
|
-
## Other information
|
|
37
|
+
## Other information
|
package/dist/aggregate-root.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { IEvent } from './interfaces';
|
|
1
|
+
import { IEvent, IEventHandler } from './interfaces';
|
|
2
|
+
import { Type } from '@nestjs/common';
|
|
2
3
|
declare const INTERNAL_EVENTS: unique symbol;
|
|
3
4
|
declare const IS_AUTO_COMMIT_ENABLED: unique symbol;
|
|
4
5
|
export declare abstract class AggregateRoot<EventBase extends IEvent = IEvent> {
|
|
@@ -13,7 +14,7 @@ export declare abstract class AggregateRoot<EventBase extends IEvent = IEvent> {
|
|
|
13
14
|
getUncommittedEvents(): EventBase[];
|
|
14
15
|
loadFromHistory(history: EventBase[]): void;
|
|
15
16
|
apply<T extends EventBase = EventBase>(event: T, isFromHistory?: boolean): void;
|
|
16
|
-
protected getEventHandler<T extends EventBase = EventBase>(event: T):
|
|
17
|
+
protected getEventHandler<T extends EventBase = EventBase>(event: T): Type<IEventHandler> | undefined;
|
|
17
18
|
protected getEventName(event: any): string;
|
|
18
19
|
}
|
|
19
20
|
export {};
|
package/dist/command-bus.d.ts
CHANGED
|
@@ -12,10 +12,10 @@ export declare class CommandBus<CommandBase extends ICommand = ICommand> extends
|
|
|
12
12
|
get publisher(): ICommandPublisher<CommandBase>;
|
|
13
13
|
set publisher(_publisher: ICommandPublisher<CommandBase>);
|
|
14
14
|
execute<T extends CommandBase, R = any>(command: T): Promise<R>;
|
|
15
|
-
bind<T extends CommandBase>(handler: ICommandHandler<T>,
|
|
15
|
+
bind<T extends CommandBase>(handler: ICommandHandler<T>, id: string): void;
|
|
16
16
|
register(handlers?: CommandHandlerType[]): void;
|
|
17
17
|
protected registerHandler(handler: CommandHandlerType): void;
|
|
18
|
-
private
|
|
19
|
-
private
|
|
18
|
+
private getCommandId;
|
|
19
|
+
private reflectCommandId;
|
|
20
20
|
private useDefaultPublisher;
|
|
21
21
|
}
|
package/dist/command-bus.js
CHANGED
|
@@ -32,16 +32,16 @@ let CommandBus = class CommandBus extends observable_bus_1.ObservableBus {
|
|
|
32
32
|
this._publisher = _publisher;
|
|
33
33
|
}
|
|
34
34
|
execute(command) {
|
|
35
|
-
const
|
|
36
|
-
const handler = this.handlers.get(
|
|
35
|
+
const commandId = this.getCommandId(command);
|
|
36
|
+
const handler = this.handlers.get(commandId);
|
|
37
37
|
if (!handler) {
|
|
38
|
-
throw new command_not_found_exception_1.CommandHandlerNotFoundException(
|
|
38
|
+
throw new command_not_found_exception_1.CommandHandlerNotFoundException(commandId);
|
|
39
39
|
}
|
|
40
40
|
this.subject$.next(command);
|
|
41
41
|
return handler.execute(command);
|
|
42
42
|
}
|
|
43
|
-
bind(handler,
|
|
44
|
-
this.handlers.set(
|
|
43
|
+
bind(handler, id) {
|
|
44
|
+
this.handlers.set(id, handler);
|
|
45
45
|
}
|
|
46
46
|
register(handlers = []) {
|
|
47
47
|
handlers.forEach((handler) => this.registerHandler(handler));
|
|
@@ -51,25 +51,31 @@ let CommandBus = class CommandBus extends observable_bus_1.ObservableBus {
|
|
|
51
51
|
if (!instance) {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
const target = this.
|
|
54
|
+
const target = this.reflectCommandId(handler);
|
|
55
55
|
if (!target) {
|
|
56
56
|
throw new index_1.InvalidCommandHandlerException();
|
|
57
57
|
}
|
|
58
|
-
this.bind(instance, target
|
|
58
|
+
this.bind(instance, target);
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
const { constructor } = Object.getPrototypeOf(command);
|
|
62
|
-
|
|
60
|
+
getCommandId(command) {
|
|
61
|
+
const { constructor: commandType } = Object.getPrototypeOf(command);
|
|
62
|
+
const commandMetadata = Reflect.getMetadata(constants_1.COMMAND_METADATA, commandType);
|
|
63
|
+
if (!commandMetadata) {
|
|
64
|
+
throw new command_not_found_exception_1.CommandHandlerNotFoundException(commandType.name);
|
|
65
|
+
}
|
|
66
|
+
return commandMetadata.id;
|
|
63
67
|
}
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
reflectCommandId(handler) {
|
|
69
|
+
const command = Reflect.getMetadata(constants_1.COMMAND_HANDLER_METADATA, handler);
|
|
70
|
+
const commandMetadata = Reflect.getMetadata(constants_1.COMMAND_METADATA, command);
|
|
71
|
+
return commandMetadata.id;
|
|
66
72
|
}
|
|
67
73
|
useDefaultPublisher() {
|
|
68
74
|
this._publisher = new default_command_pubsub_1.DefaultCommandPubSub(this.subject$);
|
|
69
75
|
}
|
|
70
76
|
};
|
|
71
77
|
CommandBus = __decorate([
|
|
72
|
-
common_1.Injectable(),
|
|
78
|
+
(0, common_1.Injectable)(),
|
|
73
79
|
__metadata("design:paramtypes", [core_1.ModuleRef])
|
|
74
80
|
], CommandBus);
|
|
75
81
|
exports.CommandBus = CommandBus;
|
package/dist/cqrs.module.js
CHANGED
|
@@ -32,7 +32,7 @@ let CqrsModule = class CqrsModule {
|
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
CqrsModule = __decorate([
|
|
35
|
-
common_1.Module({
|
|
35
|
+
(0, common_1.Module)({
|
|
36
36
|
providers: [command_bus_1.CommandBus, query_bus_1.QueryBus, event_bus_1.EventBus, event_publisher_1.EventPublisher, explorer_service_1.ExplorerService],
|
|
37
37
|
exports: [command_bus_1.CommandBus, query_bus_1.QueryBus, event_bus_1.EventBus, event_publisher_1.EventPublisher],
|
|
38
38
|
}),
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CommandHandler = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
6
7
|
/**
|
|
7
8
|
* Decorator that marks a class as a Nest command handler. A command handler
|
|
8
9
|
* handles commands (actions) executed by your application code.
|
|
@@ -15,6 +16,9 @@ const constants_1 = require("./constants");
|
|
|
15
16
|
*/
|
|
16
17
|
const CommandHandler = (command) => {
|
|
17
18
|
return (target) => {
|
|
19
|
+
if (!Reflect.hasMetadata(constants_1.COMMAND_METADATA, command)) {
|
|
20
|
+
Reflect.defineMetadata(constants_1.COMMAND_METADATA, { id: (0, uuid_1.v4)() }, command);
|
|
21
|
+
}
|
|
18
22
|
Reflect.defineMetadata(constants_1.COMMAND_HANDLER_METADATA, command, target);
|
|
19
23
|
};
|
|
20
24
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export declare const COMMAND_METADATA = "__command__";
|
|
1
2
|
export declare const COMMAND_HANDLER_METADATA = "__commandHandler__";
|
|
3
|
+
export declare const QUERY_METADATA = "__query__";
|
|
2
4
|
export declare const QUERY_HANDLER_METADATA = "__queryHandler__";
|
|
3
|
-
export declare const EVENTS_HANDLER_METADATA = "
|
|
5
|
+
export declare const EVENTS_HANDLER_METADATA = "__eventsHandler__";
|
|
4
6
|
export declare const SAGA_METADATA = "__saga__";
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SAGA_METADATA = exports.EVENTS_HANDLER_METADATA = exports.QUERY_HANDLER_METADATA = exports.COMMAND_HANDLER_METADATA = void 0;
|
|
3
|
+
exports.SAGA_METADATA = exports.EVENTS_HANDLER_METADATA = exports.QUERY_HANDLER_METADATA = exports.QUERY_METADATA = exports.COMMAND_HANDLER_METADATA = exports.COMMAND_METADATA = void 0;
|
|
4
|
+
exports.COMMAND_METADATA = '__command__';
|
|
4
5
|
exports.COMMAND_HANDLER_METADATA = '__commandHandler__';
|
|
6
|
+
exports.QUERY_METADATA = '__query__';
|
|
5
7
|
exports.QUERY_HANDLER_METADATA = '__queryHandler__';
|
|
6
|
-
exports.EVENTS_HANDLER_METADATA = '
|
|
8
|
+
exports.EVENTS_HANDLER_METADATA = '__eventsHandler__';
|
|
7
9
|
exports.SAGA_METADATA = '__saga__';
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.QueryHandler = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
6
7
|
/**
|
|
7
8
|
* Decorator that marks a class as a Nest query handler. A query handler
|
|
8
9
|
* handles queries executed by your application code.
|
|
@@ -15,6 +16,9 @@ const constants_1 = require("./constants");
|
|
|
15
16
|
*/
|
|
16
17
|
const QueryHandler = (query) => {
|
|
17
18
|
return (target) => {
|
|
19
|
+
if (!Reflect.hasMetadata(constants_1.QUERY_METADATA, query)) {
|
|
20
|
+
Reflect.defineMetadata(constants_1.QUERY_METADATA, { id: (0, uuid_1.v4)() }, query);
|
|
21
|
+
}
|
|
18
22
|
Reflect.defineMetadata(constants_1.QUERY_HANDLER_METADATA, query, target);
|
|
19
23
|
};
|
|
20
24
|
};
|
package/dist/event-bus.js
CHANGED
|
@@ -78,10 +78,10 @@ let EventBus = class EventBus extends utils_1.ObservableBus {
|
|
|
78
78
|
eventsNames.map((event) => this.bind(instance, event.name));
|
|
79
79
|
}
|
|
80
80
|
ofEventName(name) {
|
|
81
|
-
return this.subject$.pipe(operators_1.filter((event) => this.getEventName(event) === name));
|
|
81
|
+
return this.subject$.pipe((0, operators_1.filter)((event) => this.getEventName(event) === name));
|
|
82
82
|
}
|
|
83
83
|
registerSaga(saga) {
|
|
84
|
-
if (!util_1.isFunction(saga)) {
|
|
84
|
+
if (!(0, util_1.isFunction)(saga)) {
|
|
85
85
|
throw new exceptions_1.InvalidSagaException();
|
|
86
86
|
}
|
|
87
87
|
const stream$ = saga(this);
|
|
@@ -89,7 +89,7 @@ let EventBus = class EventBus extends utils_1.ObservableBus {
|
|
|
89
89
|
throw new exceptions_1.InvalidSagaException();
|
|
90
90
|
}
|
|
91
91
|
const subscription = stream$
|
|
92
|
-
.pipe(operators_1.filter((e) => !!e))
|
|
92
|
+
.pipe((0, operators_1.filter)((e) => !!e))
|
|
93
93
|
.subscribe((command) => this.commandBus.execute(command));
|
|
94
94
|
this.subscriptions.push(subscription);
|
|
95
95
|
}
|
|
@@ -101,7 +101,7 @@ let EventBus = class EventBus extends utils_1.ObservableBus {
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
EventBus = __decorate([
|
|
104
|
-
common_1.Injectable(),
|
|
104
|
+
(0, common_1.Injectable)(),
|
|
105
105
|
__metadata("design:paramtypes", [command_bus_1.CommandBus,
|
|
106
106
|
core_1.ModuleRef])
|
|
107
107
|
], EventBus);
|
package/dist/event-publisher.js
CHANGED
|
@@ -39,7 +39,7 @@ let EventPublisher = class EventPublisher {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
EventPublisher = __decorate([
|
|
42
|
-
common_1.Injectable(),
|
|
42
|
+
(0, common_1.Injectable)(),
|
|
43
43
|
__metadata("design:paramtypes", [event_bus_1.EventBus])
|
|
44
44
|
], EventPublisher);
|
|
45
45
|
exports.EventPublisher = EventPublisher;
|
|
@@ -12,6 +12,6 @@ const operators_1 = require("rxjs/operators");
|
|
|
12
12
|
*/
|
|
13
13
|
function ofType(...types) {
|
|
14
14
|
const isInstanceOf = (event) => !!types.find((classType) => event instanceof classType);
|
|
15
|
-
return (source) => source.pipe(operators_1.filter(isInstanceOf));
|
|
15
|
+
return (source) => source.pipe((0, operators_1.filter)(isInstanceOf));
|
|
16
16
|
}
|
|
17
17
|
exports.ofType = ofType;
|
package/dist/query-bus.d.ts
CHANGED
|
@@ -12,10 +12,10 @@ export declare class QueryBus<QueryBase extends IQuery = IQuery> extends Observa
|
|
|
12
12
|
get publisher(): IQueryPublisher<QueryBase>;
|
|
13
13
|
set publisher(_publisher: IQueryPublisher<QueryBase>);
|
|
14
14
|
execute<T extends QueryBase, TResult = any>(query: T): Promise<TResult>;
|
|
15
|
-
bind<T extends QueryBase, TResult = any>(handler: IQueryHandler<T, TResult>,
|
|
15
|
+
bind<T extends QueryBase, TResult = any>(handler: IQueryHandler<T, TResult>, queryId: string): void;
|
|
16
16
|
register(handlers?: QueryHandlerType<QueryBase>[]): void;
|
|
17
17
|
protected registerHandler(handler: QueryHandlerType<QueryBase>): void;
|
|
18
|
-
private
|
|
19
|
-
private
|
|
18
|
+
private getQueryId;
|
|
19
|
+
private reflectQueryId;
|
|
20
20
|
private useDefaultPublisher;
|
|
21
21
|
}
|
package/dist/query-bus.js
CHANGED
|
@@ -42,18 +42,18 @@ let QueryBus = class QueryBus extends observable_bus_1.ObservableBus {
|
|
|
42
42
|
}
|
|
43
43
|
execute(query) {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const
|
|
46
|
-
const handler = this.handlers.get(
|
|
45
|
+
const queryId = this.getQueryId(query);
|
|
46
|
+
const handler = this.handlers.get(queryId);
|
|
47
47
|
if (!handler) {
|
|
48
|
-
throw new exceptions_1.QueryHandlerNotFoundException(
|
|
48
|
+
throw new exceptions_1.QueryHandlerNotFoundException(queryId);
|
|
49
49
|
}
|
|
50
50
|
this.subject$.next(query);
|
|
51
51
|
const result = yield handler.execute(query);
|
|
52
52
|
return result;
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
bind(handler,
|
|
56
|
-
this.handlers.set(
|
|
55
|
+
bind(handler, queryId) {
|
|
56
|
+
this.handlers.set(queryId, handler);
|
|
57
57
|
}
|
|
58
58
|
register(handlers = []) {
|
|
59
59
|
handlers.forEach((handler) => this.registerHandler(handler));
|
|
@@ -63,25 +63,31 @@ let QueryBus = class QueryBus extends observable_bus_1.ObservableBus {
|
|
|
63
63
|
if (!instance) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
const target = this.
|
|
66
|
+
const target = this.reflectQueryId(handler);
|
|
67
67
|
if (!target) {
|
|
68
68
|
throw new invalid_query_handler_exception_1.InvalidQueryHandlerException();
|
|
69
69
|
}
|
|
70
|
-
this.bind(instance, target
|
|
70
|
+
this.bind(instance, target);
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
const { constructor } = Object.getPrototypeOf(query);
|
|
74
|
-
|
|
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);
|
|
77
|
+
}
|
|
78
|
+
return queryMetadata.id;
|
|
75
79
|
}
|
|
76
|
-
|
|
77
|
-
|
|
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;
|
|
78
84
|
}
|
|
79
85
|
useDefaultPublisher() {
|
|
80
86
|
this._publisher = new default_query_pubsub_1.DefaultQueryPubSub(this.subject$);
|
|
81
87
|
}
|
|
82
88
|
};
|
|
83
89
|
QueryBus = __decorate([
|
|
84
|
-
common_1.Injectable(),
|
|
90
|
+
(0, common_1.Injectable)(),
|
|
85
91
|
__metadata("design:paramtypes", [core_1.ModuleRef])
|
|
86
92
|
], QueryBus);
|
|
87
93
|
exports.QueryBus = QueryBus;
|
|
@@ -47,7 +47,7 @@ let ExplorerService = class ExplorerService {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
ExplorerService = __decorate([
|
|
50
|
-
common_1.Injectable(),
|
|
50
|
+
(0, common_1.Injectable)(),
|
|
51
51
|
__metadata("design:paramtypes", [modules_container_1.ModulesContainer])
|
|
52
52
|
], ExplorerService);
|
|
53
53
|
exports.ExplorerService = ExplorerService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/cqrs",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.1",
|
|
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,27 +16,30 @@
|
|
|
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": "
|
|
21
|
-
"@commitlint/config-angular": "
|
|
22
|
-
"@nestjs/common": "
|
|
23
|
-
"@nestjs/core": "
|
|
24
|
-
"@types/node": "16.
|
|
25
|
-
"@types/jest": "
|
|
26
|
-
"@typescript-eslint/eslint-plugin": "
|
|
27
|
-
"@typescript-eslint/parser": "
|
|
28
|
-
"eslint": "
|
|
23
|
+
"@commitlint/cli": "15.0.0",
|
|
24
|
+
"@commitlint/config-angular": "15.0.0",
|
|
25
|
+
"@nestjs/common": "8.2.3",
|
|
26
|
+
"@nestjs/core": "8.2.3",
|
|
27
|
+
"@types/node": "16.11.12",
|
|
28
|
+
"@types/jest": "27.0.3",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "5.6.0",
|
|
30
|
+
"@typescript-eslint/parser": "5.6.0",
|
|
31
|
+
"eslint": "8.4.1",
|
|
29
32
|
"eslint-config-prettier": "8.3.0",
|
|
30
|
-
"eslint-plugin-import": "2.
|
|
31
|
-
"husky": "7.0.
|
|
32
|
-
"jest": "27.
|
|
33
|
-
"lint-staged": "
|
|
34
|
-
"prettier": "2.
|
|
33
|
+
"eslint-plugin-import": "2.25.3",
|
|
34
|
+
"husky": "7.0.4",
|
|
35
|
+
"jest": "27.4.3",
|
|
36
|
+
"lint-staged": "12.1.2",
|
|
37
|
+
"prettier": "2.5.1",
|
|
35
38
|
"reflect-metadata": "0.1.13",
|
|
36
|
-
"release-it": "14.
|
|
37
|
-
"rxjs": "
|
|
38
|
-
"ts-jest": "27.
|
|
39
|
-
"typescript": "4.
|
|
39
|
+
"release-it": "14.11.8",
|
|
40
|
+
"rxjs": "7.4.0",
|
|
41
|
+
"ts-jest": "27.1.1",
|
|
42
|
+
"typescript": "4.5.2"
|
|
40
43
|
},
|
|
41
44
|
"peerDependencies": {
|
|
42
45
|
"@nestjs/common": "^8.0.0",
|
|
@@ -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>
|