@nestjs/cqrs 11.0.2 → 12.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 +3 -3
- package/.nvmrc +1 -0
- package/README.md +0 -1
- package/dist/aggregate-root.d.ts +3 -67
- package/dist/aggregate-root.js +6 -83
- package/dist/classes/command.d.ts +2 -2
- package/dist/classes/command.js +2 -6
- package/dist/classes/constants.js +1 -4
- package/dist/classes/index.d.ts +2 -2
- package/dist/classes/index.js +2 -18
- package/dist/classes/query.d.ts +2 -2
- package/dist/classes/query.js +2 -6
- package/dist/command-bus.d.ts +8 -5
- package/dist/command-bus.js +32 -32
- package/dist/constants.js +1 -4
- package/dist/cqrs.module.d.ts +8 -5
- package/dist/cqrs.module.js +37 -37
- package/dist/decorators/command-handler.decorator.d.ts +3 -1
- package/dist/decorators/command-handler.decorator.js +11 -13
- package/dist/decorators/constants.js +7 -10
- package/dist/decorators/events-handler.decorator.d.ts +3 -1
- package/dist/decorators/events-handler.decorator.js +12 -14
- package/dist/decorators/index.d.ts +5 -5
- package/dist/decorators/index.js +5 -21
- package/dist/decorators/publishable.decorator.d.ts +2 -0
- package/dist/decorators/publishable.decorator.js +5 -6
- package/dist/decorators/query-handler.decorator.d.ts +3 -1
- package/dist/decorators/query-handler.decorator.js +11 -13
- package/dist/decorators/saga.decorator.d.ts +2 -0
- package/dist/decorators/saga.decorator.js +7 -9
- package/dist/event-bus.d.ts +13 -8
- package/dist/event-bus.js +54 -51
- package/dist/event-publisher.d.ts +9 -7
- package/dist/event-publisher.js +10 -10
- package/dist/exceptions/command-not-found.exception.d.ts +3 -0
- package/dist/exceptions/command-not-found.exception.js +4 -5
- package/dist/exceptions/index.d.ts +7 -7
- package/dist/exceptions/index.js +7 -23
- package/dist/exceptions/invalid-command-handler.exception.d.ts +3 -0
- package/dist/exceptions/invalid-command-handler.exception.js +4 -5
- package/dist/exceptions/invalid-events-handler.exception.d.ts +3 -0
- package/dist/exceptions/invalid-events-handler.exception.js +4 -5
- package/dist/exceptions/invalid-query-handler.exception.js +1 -5
- package/dist/exceptions/invalid-saga.exception.d.ts +3 -0
- package/dist/exceptions/invalid-saga.exception.js +4 -5
- package/dist/exceptions/query-not-found.exception.d.ts +3 -0
- package/dist/exceptions/query-not-found.exception.js +4 -5
- package/dist/exceptions/unsupported-saga-scope.exception.d.ts +3 -0
- package/dist/exceptions/unsupported-saga-scope.exception.js +4 -5
- package/dist/helpers/default-command-pubsub.d.ts +1 -1
- package/dist/helpers/default-command-pubsub.js +1 -5
- package/dist/helpers/default-event-id-provider.d.ts +1 -1
- package/dist/helpers/default-event-id-provider.js +3 -6
- package/dist/helpers/default-pubsub.d.ts +1 -1
- package/dist/helpers/default-pubsub.js +1 -5
- package/dist/helpers/default-query-pubsub.d.ts +1 -1
- package/dist/helpers/default-query-pubsub.js +1 -5
- package/dist/helpers/default-unhandled-exception-pubsub.d.ts +1 -1
- package/dist/helpers/default-unhandled-exception-pubsub.js +1 -5
- package/dist/index.d.ts +15 -14
- package/dist/index.js +15 -30
- package/dist/interfaces/aggregate-root.interface.d.ts +53 -0
- package/dist/interfaces/aggregate-root.interface.js +1 -0
- package/dist/interfaces/commands/command-bus.interface.d.ts +5 -3
- package/dist/interfaces/commands/command-bus.interface.js +1 -2
- package/dist/interfaces/commands/command-handler.interface.d.ts +4 -2
- package/dist/interfaces/commands/command-handler.interface.js +1 -2
- package/dist/interfaces/commands/command-metadata.interface.js +1 -2
- package/dist/interfaces/commands/command-publisher.interface.d.ts +6 -1
- package/dist/interfaces/commands/command-publisher.interface.js +1 -2
- package/dist/interfaces/commands/command.interface.js +1 -2
- package/dist/interfaces/cqrs-module-options.interface.d.ts +17 -5
- package/dist/interfaces/cqrs-module-options.interface.js +1 -2
- package/dist/interfaces/events/event-bus.interface.d.ts +2 -2
- package/dist/interfaces/events/event-bus.interface.js +1 -2
- package/dist/interfaces/events/event-handler.interface.d.ts +1 -1
- package/dist/interfaces/events/event-handler.interface.js +1 -2
- package/dist/interfaces/events/event-id-provider.interface.d.ts +1 -1
- package/dist/interfaces/events/event-id-provider.interface.js +1 -2
- package/dist/interfaces/events/event-publisher.interface.d.ts +2 -2
- package/dist/interfaces/events/event-publisher.interface.js +1 -2
- package/dist/interfaces/events/event.interface.js +1 -2
- package/dist/interfaces/events/message-source.interface.d.ts +1 -1
- package/dist/interfaces/events/message-source.interface.js +1 -2
- package/dist/interfaces/exceptions/unhandled-exception-info.interface.d.ts +2 -2
- package/dist/interfaces/exceptions/unhandled-exception-info.interface.js +1 -2
- package/dist/interfaces/exceptions/unhandled-exception-publisher.interface.d.ts +3 -3
- package/dist/interfaces/exceptions/unhandled-exception-publisher.interface.js +1 -2
- package/dist/interfaces/index.d.ts +20 -19
- package/dist/interfaces/index.js +20 -35
- package/dist/interfaces/providers-introspection-result.interface.d.ts +4 -4
- package/dist/interfaces/providers-introspection-result.interface.js +1 -2
- package/dist/interfaces/queries/query-bus.interface.d.ts +5 -3
- package/dist/interfaces/queries/query-bus.interface.js +1 -2
- package/dist/interfaces/queries/query-handler.interface.d.ts +4 -2
- package/dist/interfaces/queries/query-handler.interface.js +1 -2
- package/dist/interfaces/queries/query-metadata.interface.js +1 -2
- package/dist/interfaces/queries/query-publisher.interface.d.ts +6 -1
- package/dist/interfaces/queries/query-publisher.interface.js +1 -2
- package/dist/interfaces/queries/query-result.interface.js +1 -2
- package/dist/interfaces/queries/query.interface.js +1 -2
- package/dist/interfaces/saga.type.d.ts +2 -2
- package/dist/interfaces/saga.type.js +1 -2
- package/dist/mixins/index.d.ts +1 -0
- package/dist/mixins/index.js +1 -0
- package/dist/mixins/with-aggregate-root.mixin.d.ts +11 -0
- package/dist/mixins/with-aggregate-root.mixin.js +67 -0
- package/dist/operators/index.d.ts +1 -1
- package/dist/operators/index.js +1 -17
- package/dist/operators/of-type.d.ts +1 -1
- package/dist/operators/of-type.js +3 -6
- package/dist/query-bus.d.ts +8 -5
- package/dist/query-bus.js +31 -31
- package/dist/scopes/async.context.js +9 -13
- package/dist/scopes/index.d.ts +1 -1
- package/dist/scopes/index.js +1 -17
- package/dist/services/explorer.service.d.ts +5 -5
- package/dist/services/explorer.service.js +14 -20
- package/dist/storages/aggregate-root.storage.d.ts +3 -3
- package/dist/storages/aggregate-root.storage.js +1 -5
- package/dist/unhandled-exception-bus.d.ts +2 -2
- package/dist/unhandled-exception-bus.js +14 -17
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -17
- package/dist/utils/observable-bus.js +3 -7
- package/package.json +35 -27
- package/test/e2e/basic-flows.spec.ts +46 -26
- package/test/e2e/generics.spec.ts +3 -3
- package/test/e2e/request-scope.spec.ts +23 -22
- package/test/e2e/sync-event-handlers-app.spec.ts +123 -0
- package/test/e2e/unhandled-exceptions.spec.ts +36 -20
- package/tsconfig.build.json +3 -2
- package/vitest.config.e2e.ts +13 -0
- package/vitest.config.ts +8 -0
- package/dist/exceptions/invalid-module-ref.exception.d.ts +0 -3
- package/dist/exceptions/invalid-module-ref.exception.js +0 -8
- package/dist/helpers/default-get-event-id.d.ts +0 -9
- package/dist/helpers/default-get-event-id.js +0 -18
- package/dist/helpers/default-get-event-name.d.ts +0 -2
- package/dist/helpers/default-get-event-name.js +0 -8
- package/dist/interfaces/cqrs-options.interface.d.ts +0 -10
- package/dist/interfaces/cqrs-options.interface.js +0 -2
- package/dist/interfaces/event-observable.interface.d.ts +0 -4
- package/dist/interfaces/event-observable.interface.js +0 -2
- package/dist/utils/command-handler.decorator.d.ts +0 -3
- package/dist/utils/command-handler.decorator.js +0 -9
- package/dist/utils/constants.d.ts +0 -2
- package/dist/utils/constants.js +0 -4
- package/dist/utils/default-pubsub.d.ts +0 -9
- package/dist/utils/default-pubsub.js +0 -14
- package/dist/utils/events-handler.decorator.d.ts +0 -3
- package/dist/utils/events-handler.decorator.js +0 -9
- package/eslint.config.mjs +0 -42
- package/index.d.ts +0 -1
- package/index.js +0 -6
- package/jest.config.js +0 -9
- package/test/jest-e2e.json +0 -9
package/.circleci/config.yml
CHANGED
|
@@ -17,7 +17,7 @@ jobs:
|
|
|
17
17
|
build:
|
|
18
18
|
working_directory: ~/nest
|
|
19
19
|
docker:
|
|
20
|
-
- image: cimg/node:
|
|
20
|
+
- image: cimg/node:24.19.0
|
|
21
21
|
steps:
|
|
22
22
|
- checkout
|
|
23
23
|
- restore_cache:
|
|
@@ -35,7 +35,7 @@ jobs:
|
|
|
35
35
|
e2e_test:
|
|
36
36
|
working_directory: ~/nest
|
|
37
37
|
docker:
|
|
38
|
-
- image: cimg/node:
|
|
38
|
+
- image: cimg/node:24.19.0
|
|
39
39
|
steps:
|
|
40
40
|
- checkout
|
|
41
41
|
- *restore-cache
|
|
@@ -46,7 +46,7 @@ jobs:
|
|
|
46
46
|
test:
|
|
47
47
|
working_directory: ~/nest
|
|
48
48
|
docker:
|
|
49
|
-
- image: cimg/node:
|
|
49
|
+
- image: cimg/node:24.19.0
|
|
50
50
|
steps:
|
|
51
51
|
- checkout
|
|
52
52
|
- *restore-cache
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
24
|
package/README.md
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
|
13
13
|
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
|
14
14
|
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
|
|
15
|
-
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
|
|
16
15
|
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
|
17
16
|
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
|
18
17
|
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
package/dist/aggregate-root.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
|
-
import { IEvent, IEventHandler } from './interfaces';
|
|
3
|
-
declare const
|
|
4
|
-
declare const IS_AUTO_COMMIT_ENABLED: unique symbol;
|
|
2
|
+
import { IEvent, IEventHandler } from './interfaces/index.js';
|
|
3
|
+
declare const AggregateRoot_base: abstract new <T extends IEvent = IEvent>(...args: any[]) => import("./interfaces/aggregate-root.interface.js").IAggregateRoot<T> & {};
|
|
5
4
|
/**
|
|
6
5
|
* Represents an aggregate root.
|
|
7
6
|
* An aggregate root is an entity that represents a meaningful concept in the domain.
|
|
@@ -9,70 +8,7 @@ declare const IS_AUTO_COMMIT_ENABLED: unique symbol;
|
|
|
9
8
|
*
|
|
10
9
|
* @template EventBase The base type of the events.
|
|
11
10
|
*/
|
|
12
|
-
export declare abstract class AggregateRoot<EventBase extends IEvent = IEvent> {
|
|
13
|
-
[IS_AUTO_COMMIT_ENABLED]: boolean;
|
|
14
|
-
private readonly [INTERNAL_EVENTS];
|
|
15
|
-
/**
|
|
16
|
-
* Sets whether the aggregate root should automatically commit events.
|
|
17
|
-
*/
|
|
18
|
-
set autoCommit(value: boolean);
|
|
19
|
-
/**
|
|
20
|
-
* Gets whether the aggregate root should automatically commit events.
|
|
21
|
-
*/
|
|
22
|
-
get autoCommit(): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Publishes an event. Must be merged with the publisher context in order to work.
|
|
25
|
-
* @param event The event to publish.
|
|
26
|
-
*/
|
|
27
|
-
publish<T extends EventBase = EventBase>(event: T): void;
|
|
28
|
-
/**
|
|
29
|
-
* Publishes multiple events. Must be merged with the publisher context in order to work.
|
|
30
|
-
* @param events The events to publish.
|
|
31
|
-
*/
|
|
32
|
-
publishAll<T extends EventBase = EventBase>(events: T[]): void;
|
|
33
|
-
/**
|
|
34
|
-
* Commits all uncommitted events.
|
|
35
|
-
*/
|
|
36
|
-
commit(): void;
|
|
37
|
-
/**
|
|
38
|
-
* Uncommits all events.
|
|
39
|
-
*/
|
|
40
|
-
uncommit(): void;
|
|
41
|
-
/**
|
|
42
|
-
* Returns all uncommitted events.
|
|
43
|
-
* @returns All uncommitted events.
|
|
44
|
-
*/
|
|
45
|
-
getUncommittedEvents(): EventBase[];
|
|
46
|
-
/**
|
|
47
|
-
* Loads events from history.
|
|
48
|
-
* @param history The history to load.
|
|
49
|
-
*/
|
|
50
|
-
loadFromHistory(history: EventBase[]): void;
|
|
51
|
-
/**
|
|
52
|
-
* Applies an event.
|
|
53
|
-
* If auto commit is enabled, the event will be published immediately (note: must be merged with the publisher context in order to work).
|
|
54
|
-
* Otherwise, the event will be stored in the internal events array, and will be published when the commit method is called.
|
|
55
|
-
* Also, the corresponding event handler will be called (if exists).
|
|
56
|
-
* For example, if the event is called UserCreatedEvent, the "onUserCreatedEvent" method will be called.
|
|
57
|
-
*
|
|
58
|
-
* @param event The event to apply.
|
|
59
|
-
* @param isFromHistory Whether the event is from history.
|
|
60
|
-
*/
|
|
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;
|
|
11
|
+
export declare abstract class AggregateRoot<EventBase extends IEvent = IEvent> extends AggregateRoot_base<EventBase> {
|
|
76
12
|
protected getEventHandler<T extends EventBase = EventBase>(event: T): Type<IEventHandler> | undefined;
|
|
77
13
|
protected getEventName(event: any): string;
|
|
78
14
|
}
|
package/dist/aggregate-root.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
-
var _a, _b;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.AggregateRoot = void 0;
|
|
6
|
-
const INTERNAL_EVENTS = Symbol();
|
|
7
|
-
const IS_AUTO_COMMIT_ENABLED = Symbol();
|
|
1
|
+
import { WithAggregateRoot } from './mixins/index.js';
|
|
8
2
|
/**
|
|
9
3
|
* Represents an aggregate root.
|
|
10
4
|
* An aggregate root is an entity that represents a meaningful concept in the domain.
|
|
@@ -12,84 +6,13 @@ const IS_AUTO_COMMIT_ENABLED = Symbol();
|
|
|
12
6
|
*
|
|
13
7
|
* @template EventBase The base type of the events.
|
|
14
8
|
*/
|
|
15
|
-
class AggregateRoot {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this[_b] = [];
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Sets whether the aggregate root should automatically commit events.
|
|
22
|
-
*/
|
|
23
|
-
set autoCommit(value) {
|
|
24
|
-
this[IS_AUTO_COMMIT_ENABLED] = value;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Gets whether the aggregate root should automatically commit events.
|
|
28
|
-
*/
|
|
29
|
-
get autoCommit() {
|
|
30
|
-
return this[IS_AUTO_COMMIT_ENABLED];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Publishes an event. Must be merged with the publisher context in order to work.
|
|
34
|
-
* @param event The event to publish.
|
|
35
|
-
*/
|
|
36
|
-
publish(event) { }
|
|
37
|
-
/**
|
|
38
|
-
* Publishes multiple events. Must be merged with the publisher context in order to work.
|
|
39
|
-
* @param events The events to publish.
|
|
40
|
-
*/
|
|
41
|
-
publishAll(events) { }
|
|
42
|
-
/**
|
|
43
|
-
* Commits all uncommitted events.
|
|
44
|
-
*/
|
|
45
|
-
commit() {
|
|
46
|
-
this.publishAll(this[INTERNAL_EVENTS]);
|
|
47
|
-
this[INTERNAL_EVENTS].length = 0;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Uncommits all events.
|
|
51
|
-
*/
|
|
52
|
-
uncommit() {
|
|
53
|
-
this[INTERNAL_EVENTS].length = 0;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Returns all uncommitted events.
|
|
57
|
-
* @returns All uncommitted events.
|
|
58
|
-
*/
|
|
59
|
-
getUncommittedEvents() {
|
|
60
|
-
return this[INTERNAL_EVENTS];
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Loads events from history.
|
|
64
|
-
* @param history The history to load.
|
|
65
|
-
*/
|
|
66
|
-
loadFromHistory(history) {
|
|
67
|
-
history.forEach((event) => this.apply(event, true));
|
|
68
|
-
}
|
|
69
|
-
apply(event, optionsOrIsFromHistory = {}) {
|
|
70
|
-
const isFromHistory = (typeof optionsOrIsFromHistory === 'boolean'
|
|
71
|
-
? optionsOrIsFromHistory
|
|
72
|
-
: optionsOrIsFromHistory.fromHistory) ?? false;
|
|
73
|
-
const skipHandler = typeof optionsOrIsFromHistory === 'boolean'
|
|
74
|
-
? false
|
|
75
|
-
: optionsOrIsFromHistory.skipHandler;
|
|
76
|
-
if (!isFromHistory && !this.autoCommit) {
|
|
77
|
-
this[INTERNAL_EVENTS].push(event);
|
|
78
|
-
}
|
|
79
|
-
this.autoCommit && this.publish(event);
|
|
80
|
-
if (!skipHandler) {
|
|
81
|
-
const handler = this.getEventHandler(event);
|
|
82
|
-
handler && handler.call(this, event);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
9
|
+
export class AggregateRoot extends WithAggregateRoot(class {
|
|
10
|
+
}) {
|
|
11
|
+
// redeclaring protected methods to preserve typings (since this typescript version does not support the "declare" modifier on overrides)
|
|
85
12
|
getEventHandler(event) {
|
|
86
|
-
|
|
87
|
-
return this[handler];
|
|
13
|
+
return super['getEventHandler'](event);
|
|
88
14
|
}
|
|
89
15
|
getEventName(event) {
|
|
90
|
-
|
|
91
|
-
return constructor.name;
|
|
16
|
+
return super['getEventName'](event);
|
|
92
17
|
}
|
|
93
18
|
}
|
|
94
|
-
exports.AggregateRoot = AggregateRoot;
|
|
95
|
-
_a = IS_AUTO_COMMIT_ENABLED, _b = INTERNAL_EVENTS;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ICommand } from '../interfaces';
|
|
2
|
-
import { RESULT_TYPE_SYMBOL } from './constants';
|
|
1
|
+
import { ICommand } from '../interfaces/index.js';
|
|
2
|
+
import { RESULT_TYPE_SYMBOL } from './constants.js';
|
|
3
3
|
/**
|
|
4
4
|
* Utility type to extract the result type of a command.
|
|
5
5
|
*/
|
package/dist/classes/command.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Command = void 0;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
class Command {
|
|
1
|
+
import { RESULT_TYPE_SYMBOL } from './constants.js';
|
|
2
|
+
export class Command {
|
|
6
3
|
}
|
|
7
|
-
exports.Command = Command;
|
package/dist/classes/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './command';
|
|
2
|
-
export * from './query';
|
|
1
|
+
export * from './command.js';
|
|
2
|
+
export * from './query.js';
|
package/dist/classes/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./command"), exports);
|
|
18
|
-
__exportStar(require("./query"), exports);
|
|
1
|
+
export * from './command.js';
|
|
2
|
+
export * from './query.js';
|
package/dist/classes/query.d.ts
CHANGED
package/dist/classes/query.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Query = void 0;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
class Query {
|
|
1
|
+
import { RESULT_TYPE_SYMBOL } from './constants.js';
|
|
2
|
+
export class Query {
|
|
6
3
|
}
|
|
7
|
-
exports.Query = Query;
|
package/dist/command-bus.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
|
-
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
|
3
|
+
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper.js';
|
|
4
4
|
import 'reflect-metadata';
|
|
5
|
-
import { Command } from './classes';
|
|
6
|
-
import { CqrsModuleOptions, ICommand, ICommandBus, ICommandHandler, ICommandPublisher } from './interfaces/index';
|
|
7
|
-
import { AsyncContext } from './scopes/async.context';
|
|
8
|
-
import { ObservableBus } from './utils/observable-bus';
|
|
5
|
+
import { Command } from './classes/index.js';
|
|
6
|
+
import { CqrsModuleOptions, ICommand, ICommandBus, ICommandHandler, ICommandPublisher } from './interfaces/index.js';
|
|
7
|
+
import { AsyncContext } from './scopes/async.context.js';
|
|
8
|
+
import { ObservableBus } from './utils/observable-bus.js';
|
|
9
9
|
export type CommandHandlerType<T extends ICommand = ICommand> = Type<ICommandHandler<T>>;
|
|
10
|
+
/**
|
|
11
|
+
* @publicApi
|
|
12
|
+
*/
|
|
10
13
|
export declare class CommandBus<CommandBase extends ICommand = ICommand> extends ObservableBus<CommandBase> implements ICommandBus<CommandBase> {
|
|
11
14
|
private readonly moduleRef;
|
|
12
15
|
private readonly options?;
|
package/dist/command-bus.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -12,24 +11,25 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
12
|
};
|
|
14
13
|
var CommandBus_1;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
import { Inject, Injectable, Logger, Optional } from '@nestjs/common';
|
|
15
|
+
import { ModuleRef } from '@nestjs/core';
|
|
16
|
+
import 'reflect-metadata';
|
|
17
|
+
import { CQRS_MODULE_OPTIONS } from './constants.js';
|
|
18
|
+
import { COMMAND_HANDLER_METADATA, COMMAND_METADATA, } from './decorators/constants.js';
|
|
19
|
+
import { CommandHandlerNotFoundException } from './exceptions/command-not-found.exception.js';
|
|
20
|
+
import { DefaultCommandPubSub } from './helpers/default-command-pubsub.js';
|
|
21
|
+
import { InvalidCommandHandlerException } from './index.js';
|
|
22
|
+
import { AsyncContext } from './scopes/async.context.js';
|
|
23
|
+
import { ObservableBus } from './utils/observable-bus.js';
|
|
24
|
+
/**
|
|
25
|
+
* @publicApi
|
|
26
|
+
*/
|
|
27
|
+
let CommandBus = CommandBus_1 = class CommandBus extends ObservableBus {
|
|
28
28
|
constructor(moduleRef, options) {
|
|
29
29
|
super();
|
|
30
30
|
this.moduleRef = moduleRef;
|
|
31
31
|
this.options = options;
|
|
32
|
-
this.logger = new
|
|
32
|
+
this.logger = new Logger(CommandBus_1.name);
|
|
33
33
|
this.handlers = new Map();
|
|
34
34
|
if (this.options?.commandPublisher) {
|
|
35
35
|
this._publisher = this.options.commandPublisher;
|
|
@@ -64,7 +64,7 @@ let CommandBus = CommandBus_1 = class CommandBus extends observable_bus_1.Observ
|
|
|
64
64
|
const executeFn = this.handlers.get(commandId);
|
|
65
65
|
if (!executeFn) {
|
|
66
66
|
const commandName = this.getCommandName(command);
|
|
67
|
-
throw new
|
|
67
|
+
throw new CommandHandlerNotFoundException(commandName);
|
|
68
68
|
}
|
|
69
69
|
this._publisher.publish(command);
|
|
70
70
|
return executeFn(command, context);
|
|
@@ -73,14 +73,14 @@ let CommandBus = CommandBus_1 = class CommandBus extends observable_bus_1.Observ
|
|
|
73
73
|
if (handler.isDependencyTreeStatic()) {
|
|
74
74
|
const instance = handler.instance;
|
|
75
75
|
if (!instance.execute) {
|
|
76
|
-
throw new
|
|
76
|
+
throw new InvalidCommandHandlerException();
|
|
77
77
|
}
|
|
78
78
|
this.handlers.set(id, (command) => instance.execute(command));
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
this.handlers.set(id, async (command, context) => {
|
|
82
|
-
context ??=
|
|
83
|
-
if (!
|
|
82
|
+
context ??= AsyncContext.of(command) ?? new AsyncContext();
|
|
83
|
+
if (!AsyncContext.isAttached(context)) {
|
|
84
84
|
// Commands returned by sagas may already have an async context set
|
|
85
85
|
// and a corresponding request provider registered.
|
|
86
86
|
this.moduleRef.registerRequestByContextId(context, context.id);
|
|
@@ -96,10 +96,10 @@ let CommandBus = CommandBus_1 = class CommandBus extends observable_bus_1.Observ
|
|
|
96
96
|
handlers.forEach((handler) => this.registerHandler(handler));
|
|
97
97
|
}
|
|
98
98
|
registerHandler(handler) {
|
|
99
|
-
const typeRef = handler.metatype;
|
|
99
|
+
const typeRef = (handler.inject ? handler.instance?.constructor : handler.metatype);
|
|
100
100
|
const target = this.reflectCommandId(typeRef);
|
|
101
101
|
if (!target) {
|
|
102
|
-
throw new
|
|
102
|
+
throw new InvalidCommandHandlerException();
|
|
103
103
|
}
|
|
104
104
|
if (this.handlers.has(target)) {
|
|
105
105
|
this.logger.warn(`Command handler [${typeRef.name}] is already registered. Overriding previously registered handler.`);
|
|
@@ -108,9 +108,9 @@ let CommandBus = CommandBus_1 = class CommandBus extends observable_bus_1.Observ
|
|
|
108
108
|
}
|
|
109
109
|
getCommandId(command) {
|
|
110
110
|
const { constructor: commandType } = Object.getPrototypeOf(command);
|
|
111
|
-
const commandMetadata = Reflect.getMetadata(
|
|
111
|
+
const commandMetadata = Reflect.getMetadata(COMMAND_METADATA, commandType);
|
|
112
112
|
if (!commandMetadata) {
|
|
113
|
-
throw new
|
|
113
|
+
throw new CommandHandlerNotFoundException(commandType.name);
|
|
114
114
|
}
|
|
115
115
|
return commandMetadata.id;
|
|
116
116
|
}
|
|
@@ -119,18 +119,18 @@ let CommandBus = CommandBus_1 = class CommandBus extends observable_bus_1.Observ
|
|
|
119
119
|
return constructor.name;
|
|
120
120
|
}
|
|
121
121
|
reflectCommandId(handler) {
|
|
122
|
-
const command = Reflect.getMetadata(
|
|
123
|
-
const commandMetadata = Reflect.getMetadata(
|
|
122
|
+
const command = Reflect.getMetadata(COMMAND_HANDLER_METADATA, handler);
|
|
123
|
+
const commandMetadata = Reflect.getMetadata(COMMAND_METADATA, command);
|
|
124
124
|
return commandMetadata.id;
|
|
125
125
|
}
|
|
126
126
|
useDefaultPublisher() {
|
|
127
|
-
this._publisher = new
|
|
127
|
+
this._publisher = new DefaultCommandPubSub(this.subject$);
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
(
|
|
133
|
-
__param(1, (
|
|
134
|
-
|
|
135
|
-
__metadata("design:paramtypes", [core_1.ModuleRef, Object])
|
|
130
|
+
CommandBus = CommandBus_1 = __decorate([
|
|
131
|
+
Injectable(),
|
|
132
|
+
__param(1, Optional()),
|
|
133
|
+
__param(1, Inject(CQRS_MODULE_OPTIONS)),
|
|
134
|
+
__metadata("design:paramtypes", [ModuleRef, Object])
|
|
136
135
|
], CommandBus);
|
|
136
|
+
export { CommandBus };
|
package/dist/constants.js
CHANGED
package/dist/cqrs.module.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { DynamicModule, OnApplicationBootstrap } from '@nestjs/common';
|
|
2
|
-
import { CommandBus } from './command-bus';
|
|
3
|
-
import { EventBus } from './event-bus';
|
|
4
|
-
import { CqrsModuleAsyncOptions, CqrsModuleOptions, IEvent } from './interfaces';
|
|
5
|
-
import { QueryBus } from './query-bus';
|
|
6
|
-
import { ExplorerService } from './services/explorer.service';
|
|
2
|
+
import { CommandBus } from './command-bus.js';
|
|
3
|
+
import { EventBus } from './event-bus.js';
|
|
4
|
+
import { CqrsModuleAsyncOptions, CqrsModuleOptions, IEvent } from './interfaces/index.js';
|
|
5
|
+
import { QueryBus } from './query-bus.js';
|
|
6
|
+
import { ExplorerService } from './services/explorer.service.js';
|
|
7
|
+
/**
|
|
8
|
+
* @publicApi
|
|
9
|
+
*/
|
|
7
10
|
export declare class CqrsModule<EventBase extends IEvent = IEvent> implements OnApplicationBootstrap {
|
|
8
11
|
private readonly explorerService;
|
|
9
12
|
private readonly eventBus;
|
package/dist/cqrs.module.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -9,24 +8,25 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
10
|
var CqrsModule_1;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
import { Module, } from '@nestjs/common';
|
|
12
|
+
import { CommandBus } from './command-bus.js';
|
|
13
|
+
import { CQRS_MODULE_OPTIONS } from './constants.js';
|
|
14
|
+
import { EventBus } from './event-bus.js';
|
|
15
|
+
import { EventPublisher } from './event-publisher.js';
|
|
16
|
+
import { QueryBus } from './query-bus.js';
|
|
17
|
+
import { ExplorerService } from './services/explorer.service.js';
|
|
18
|
+
import { UnhandledExceptionBus } from './unhandled-exception-bus.js';
|
|
19
|
+
import { AggregateRootStorage } from './storages/aggregate-root.storage.js';
|
|
20
|
+
/**
|
|
21
|
+
* @publicApi
|
|
22
|
+
*/
|
|
23
23
|
let CqrsModule = CqrsModule_1 = class CqrsModule {
|
|
24
24
|
static forRoot(options) {
|
|
25
25
|
return {
|
|
26
26
|
module: CqrsModule_1,
|
|
27
27
|
providers: [
|
|
28
28
|
{
|
|
29
|
-
provide:
|
|
29
|
+
provide: CQRS_MODULE_OPTIONS,
|
|
30
30
|
useValue: options ?? {},
|
|
31
31
|
},
|
|
32
32
|
],
|
|
@@ -39,14 +39,14 @@ let CqrsModule = CqrsModule_1 = class CqrsModule {
|
|
|
39
39
|
global: true,
|
|
40
40
|
imports: options.imports || [],
|
|
41
41
|
providers: [...this.createAsyncProviders(options)],
|
|
42
|
-
exports: [
|
|
42
|
+
exports: [CQRS_MODULE_OPTIONS],
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
static createAsyncProviders(options) {
|
|
46
46
|
if (options.useValue) {
|
|
47
47
|
return [
|
|
48
48
|
{
|
|
49
|
-
provide:
|
|
49
|
+
provide: CQRS_MODULE_OPTIONS,
|
|
50
50
|
useValue: options.useValue,
|
|
51
51
|
},
|
|
52
52
|
];
|
|
@@ -54,7 +54,7 @@ let CqrsModule = CqrsModule_1 = class CqrsModule {
|
|
|
54
54
|
if (options.useFactory) {
|
|
55
55
|
return [
|
|
56
56
|
{
|
|
57
|
-
provide:
|
|
57
|
+
provide: CQRS_MODULE_OPTIONS,
|
|
58
58
|
useFactory: options.useFactory,
|
|
59
59
|
inject: options.inject || [],
|
|
60
60
|
},
|
|
@@ -67,7 +67,7 @@ let CqrsModule = CqrsModule_1 = class CqrsModule {
|
|
|
67
67
|
useClass: options.useClass,
|
|
68
68
|
},
|
|
69
69
|
{
|
|
70
|
-
provide:
|
|
70
|
+
provide: CQRS_MODULE_OPTIONS,
|
|
71
71
|
useFactory: async (optionsFactory) => optionsFactory.createCqrsOptions(),
|
|
72
72
|
inject: [options.useClass],
|
|
73
73
|
},
|
|
@@ -76,7 +76,7 @@ let CqrsModule = CqrsModule_1 = class CqrsModule {
|
|
|
76
76
|
if (options.useExisting) {
|
|
77
77
|
return [
|
|
78
78
|
{
|
|
79
|
-
provide:
|
|
79
|
+
provide: CQRS_MODULE_OPTIONS,
|
|
80
80
|
useFactory: async (optionsFactory) => optionsFactory.createCqrsOptions(),
|
|
81
81
|
inject: [options.useExisting],
|
|
82
82
|
},
|
|
@@ -96,30 +96,30 @@ let CqrsModule = CqrsModule_1 = class CqrsModule {
|
|
|
96
96
|
this.commandBus.register(commands);
|
|
97
97
|
this.queryBus.register(queries);
|
|
98
98
|
this.eventBus.registerSagas(sagas);
|
|
99
|
-
|
|
99
|
+
AggregateRootStorage.mergeContext(this.eventBus);
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
(0, common_1.Module)({
|
|
102
|
+
CqrsModule = CqrsModule_1 = __decorate([
|
|
103
|
+
Module({
|
|
105
104
|
providers: [
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
CommandBus,
|
|
106
|
+
QueryBus,
|
|
107
|
+
EventBus,
|
|
108
|
+
UnhandledExceptionBus,
|
|
109
|
+
EventPublisher,
|
|
110
|
+
ExplorerService,
|
|
112
111
|
],
|
|
113
112
|
exports: [
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
CommandBus,
|
|
114
|
+
QueryBus,
|
|
115
|
+
EventBus,
|
|
116
|
+
UnhandledExceptionBus,
|
|
117
|
+
EventPublisher,
|
|
119
118
|
],
|
|
120
119
|
}),
|
|
121
|
-
__metadata("design:paramtypes", [
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
__metadata("design:paramtypes", [ExplorerService,
|
|
121
|
+
EventBus,
|
|
122
|
+
CommandBus,
|
|
123
|
+
QueryBus])
|
|
125
124
|
], CqrsModule);
|
|
125
|
+
export { CqrsModule };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InjectableOptions } from '@nestjs/common';
|
|
2
2
|
import 'reflect-metadata';
|
|
3
|
-
import { ICommand } from '../index';
|
|
3
|
+
import { ICommand } from '../index.js';
|
|
4
4
|
/**
|
|
5
5
|
* Decorator that marks a class as a Nest command handler. A command handler
|
|
6
6
|
* handles commands (actions) executed by your application code.
|
|
@@ -11,5 +11,7 @@ import { ICommand } from '../index';
|
|
|
11
11
|
* @param options injectable options passed on to the "@Injectable" decorator.
|
|
12
12
|
*
|
|
13
13
|
* @see https://docs.nestjs.com/recipes/cqrs#commands
|
|
14
|
+
*
|
|
15
|
+
* @publicApi
|
|
14
16
|
*/
|
|
15
17
|
export declare const CommandHandler: (command: ICommand | (new (...args: any[]) => ICommand), options?: InjectableOptions) => ClassDecorator;
|