@nestjs/cqrs 11.0.3 → 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.
Files changed (148) hide show
  1. package/.circleci/config.yml +3 -3
  2. package/.nvmrc +1 -0
  3. package/dist/aggregate-root.d.ts +3 -67
  4. package/dist/aggregate-root.js +6 -83
  5. package/dist/classes/command.d.ts +2 -2
  6. package/dist/classes/command.js +2 -6
  7. package/dist/classes/constants.js +1 -4
  8. package/dist/classes/index.d.ts +2 -2
  9. package/dist/classes/index.js +2 -18
  10. package/dist/classes/query.d.ts +2 -2
  11. package/dist/classes/query.js +2 -6
  12. package/dist/command-bus.d.ts +5 -5
  13. package/dist/command-bus.js +29 -32
  14. package/dist/constants.js +1 -4
  15. package/dist/cqrs.module.d.ts +5 -5
  16. package/dist/cqrs.module.js +34 -37
  17. package/dist/decorators/command-handler.decorator.d.ts +1 -1
  18. package/dist/decorators/command-handler.decorator.js +9 -13
  19. package/dist/decorators/constants.js +7 -10
  20. package/dist/decorators/events-handler.decorator.d.ts +1 -1
  21. package/dist/decorators/events-handler.decorator.js +9 -13
  22. package/dist/decorators/index.d.ts +5 -5
  23. package/dist/decorators/index.js +5 -21
  24. package/dist/decorators/publishable.decorator.js +3 -6
  25. package/dist/decorators/query-handler.decorator.d.ts +1 -1
  26. package/dist/decorators/query-handler.decorator.js +9 -13
  27. package/dist/decorators/saga.decorator.js +5 -9
  28. package/dist/event-bus.d.ts +10 -8
  29. package/dist/event-bus.js +51 -51
  30. package/dist/event-publisher.d.ts +6 -7
  31. package/dist/event-publisher.js +7 -10
  32. package/dist/exceptions/command-not-found.exception.js +1 -5
  33. package/dist/exceptions/index.d.ts +7 -7
  34. package/dist/exceptions/index.js +7 -23
  35. package/dist/exceptions/invalid-command-handler.exception.js +1 -5
  36. package/dist/exceptions/invalid-events-handler.exception.js +1 -5
  37. package/dist/exceptions/invalid-query-handler.exception.js +1 -5
  38. package/dist/exceptions/invalid-saga.exception.js +1 -5
  39. package/dist/exceptions/query-not-found.exception.js +1 -5
  40. package/dist/exceptions/unsupported-saga-scope.exception.js +1 -5
  41. package/dist/helpers/default-command-pubsub.d.ts +1 -1
  42. package/dist/helpers/default-command-pubsub.js +1 -5
  43. package/dist/helpers/default-event-id-provider.d.ts +1 -1
  44. package/dist/helpers/default-event-id-provider.js +3 -6
  45. package/dist/helpers/default-pubsub.d.ts +1 -1
  46. package/dist/helpers/default-pubsub.js +1 -5
  47. package/dist/helpers/default-query-pubsub.d.ts +1 -1
  48. package/dist/helpers/default-query-pubsub.js +1 -5
  49. package/dist/helpers/default-unhandled-exception-pubsub.d.ts +1 -1
  50. package/dist/helpers/default-unhandled-exception-pubsub.js +1 -5
  51. package/dist/index.d.ts +15 -14
  52. package/dist/index.js +15 -30
  53. package/dist/interfaces/aggregate-root.interface.d.ts +53 -0
  54. package/dist/interfaces/aggregate-root.interface.js +1 -0
  55. package/dist/interfaces/commands/command-bus.interface.d.ts +3 -3
  56. package/dist/interfaces/commands/command-bus.interface.js +1 -2
  57. package/dist/interfaces/commands/command-handler.interface.d.ts +2 -2
  58. package/dist/interfaces/commands/command-handler.interface.js +1 -2
  59. package/dist/interfaces/commands/command-metadata.interface.js +1 -2
  60. package/dist/interfaces/commands/command-publisher.interface.d.ts +1 -1
  61. package/dist/interfaces/commands/command-publisher.interface.js +1 -2
  62. package/dist/interfaces/commands/command.interface.js +1 -2
  63. package/dist/interfaces/cqrs-module-options.interface.d.ts +5 -5
  64. package/dist/interfaces/cqrs-module-options.interface.js +1 -2
  65. package/dist/interfaces/events/event-bus.interface.d.ts +2 -2
  66. package/dist/interfaces/events/event-bus.interface.js +1 -2
  67. package/dist/interfaces/events/event-handler.interface.d.ts +1 -1
  68. package/dist/interfaces/events/event-handler.interface.js +1 -2
  69. package/dist/interfaces/events/event-id-provider.interface.d.ts +1 -1
  70. package/dist/interfaces/events/event-id-provider.interface.js +1 -2
  71. package/dist/interfaces/events/event-publisher.interface.d.ts +2 -2
  72. package/dist/interfaces/events/event-publisher.interface.js +1 -2
  73. package/dist/interfaces/events/event.interface.js +1 -2
  74. package/dist/interfaces/events/message-source.interface.d.ts +1 -1
  75. package/dist/interfaces/events/message-source.interface.js +1 -2
  76. package/dist/interfaces/exceptions/unhandled-exception-info.interface.d.ts +2 -2
  77. package/dist/interfaces/exceptions/unhandled-exception-info.interface.js +1 -2
  78. package/dist/interfaces/exceptions/unhandled-exception-publisher.interface.d.ts +3 -3
  79. package/dist/interfaces/exceptions/unhandled-exception-publisher.interface.js +1 -2
  80. package/dist/interfaces/index.d.ts +20 -19
  81. package/dist/interfaces/index.js +20 -35
  82. package/dist/interfaces/providers-introspection-result.interface.d.ts +4 -4
  83. package/dist/interfaces/providers-introspection-result.interface.js +1 -2
  84. package/dist/interfaces/queries/query-bus.interface.d.ts +3 -3
  85. package/dist/interfaces/queries/query-bus.interface.js +1 -2
  86. package/dist/interfaces/queries/query-handler.interface.d.ts +2 -2
  87. package/dist/interfaces/queries/query-handler.interface.js +1 -2
  88. package/dist/interfaces/queries/query-metadata.interface.js +1 -2
  89. package/dist/interfaces/queries/query-publisher.interface.d.ts +1 -1
  90. package/dist/interfaces/queries/query-publisher.interface.js +1 -2
  91. package/dist/interfaces/queries/query-result.interface.js +1 -2
  92. package/dist/interfaces/queries/query.interface.js +1 -2
  93. package/dist/interfaces/saga.type.d.ts +2 -2
  94. package/dist/interfaces/saga.type.js +1 -2
  95. package/dist/mixins/index.d.ts +1 -0
  96. package/dist/mixins/index.js +1 -0
  97. package/dist/mixins/with-aggregate-root.mixin.d.ts +11 -0
  98. package/dist/mixins/with-aggregate-root.mixin.js +67 -0
  99. package/dist/operators/index.d.ts +1 -1
  100. package/dist/operators/index.js +1 -17
  101. package/dist/operators/of-type.d.ts +1 -1
  102. package/dist/operators/of-type.js +3 -6
  103. package/dist/query-bus.d.ts +5 -5
  104. package/dist/query-bus.js +28 -31
  105. package/dist/scopes/async.context.js +9 -13
  106. package/dist/scopes/index.d.ts +1 -1
  107. package/dist/scopes/index.js +1 -17
  108. package/dist/services/explorer.service.d.ts +5 -5
  109. package/dist/services/explorer.service.js +14 -20
  110. package/dist/storages/aggregate-root.storage.d.ts +3 -3
  111. package/dist/storages/aggregate-root.storage.js +1 -5
  112. package/dist/unhandled-exception-bus.d.ts +2 -2
  113. package/dist/unhandled-exception-bus.js +14 -17
  114. package/dist/utils/index.d.ts +1 -1
  115. package/dist/utils/index.js +1 -17
  116. package/dist/utils/observable-bus.js +3 -7
  117. package/package.json +34 -26
  118. package/test/e2e/basic-flows.spec.ts +46 -26
  119. package/test/e2e/generics.spec.ts +3 -3
  120. package/test/e2e/request-scope.spec.ts +23 -22
  121. package/test/e2e/sync-event-handlers-app.spec.ts +123 -0
  122. package/test/e2e/unhandled-exceptions.spec.ts +36 -20
  123. package/tsconfig.build.json +3 -2
  124. package/vitest.config.e2e.ts +13 -0
  125. package/vitest.config.ts +8 -0
  126. package/dist/exceptions/invalid-module-ref.exception.d.ts +0 -3
  127. package/dist/exceptions/invalid-module-ref.exception.js +0 -8
  128. package/dist/helpers/default-get-event-id.d.ts +0 -9
  129. package/dist/helpers/default-get-event-id.js +0 -18
  130. package/dist/helpers/default-get-event-name.d.ts +0 -2
  131. package/dist/helpers/default-get-event-name.js +0 -8
  132. package/dist/interfaces/cqrs-options.interface.d.ts +0 -10
  133. package/dist/interfaces/cqrs-options.interface.js +0 -2
  134. package/dist/interfaces/event-observable.interface.d.ts +0 -4
  135. package/dist/interfaces/event-observable.interface.js +0 -2
  136. package/dist/utils/command-handler.decorator.d.ts +0 -3
  137. package/dist/utils/command-handler.decorator.js +0 -9
  138. package/dist/utils/constants.d.ts +0 -2
  139. package/dist/utils/constants.js +0 -4
  140. package/dist/utils/default-pubsub.d.ts +0 -9
  141. package/dist/utils/default-pubsub.js +0 -14
  142. package/dist/utils/events-handler.decorator.d.ts +0 -3
  143. package/dist/utils/events-handler.decorator.js +0 -9
  144. package/eslint.config.mjs +0 -42
  145. package/index.d.ts +0 -1
  146. package/index.js +0 -6
  147. package/jest.config.js +0 -9
  148. package/test/jest-e2e.json +0 -9
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,4 +1,4 @@
1
1
  import { Observable } from 'rxjs';
2
- import { ICommand } from './commands/command.interface';
3
- import { IEvent } from './events/event.interface';
2
+ import { ICommand } from './commands/command.interface.js';
3
+ import { IEvent } from './events/event.interface.js';
4
4
  export type ISaga<EventBase extends IEvent = IEvent, CommandBase extends ICommand = ICommand> = (events$: Observable<EventBase>) => Observable<CommandBase>;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './with-aggregate-root.mixin.js';
@@ -0,0 +1 @@
1
+ export * from './with-aggregate-root.mixin.js';
@@ -0,0 +1,11 @@
1
+ import type { IEvent, IAggregateRoot } from '../interfaces/index.js';
2
+ export type AbstractConstructor<T = {}> = abstract new (...args: any[]) => T;
3
+ /**
4
+ * Adds the Aggregate Root functionality to a base class.
5
+ * An aggregate root is an entity that represents a meaningful concept in the domain.
6
+ * It is the root of an aggregate, which is a cluster of domain objects that can be treated as a single unit.
7
+ *
8
+ * @template EventBase The base type of the events.
9
+ * @template TBase The base class type.
10
+ */
11
+ export declare function WithAggregateRoot<EventBase extends IEvent = IEvent, TBase extends AbstractConstructor = AbstractConstructor>(Base: TBase): abstract new <T extends IEvent = EventBase>(...args: any[]) => IAggregateRoot<T> & InstanceType<TBase>;
@@ -0,0 +1,67 @@
1
+ const INTERNAL_EVENTS = Symbol();
2
+ const IS_AUTO_COMMIT_ENABLED = Symbol();
3
+ /**
4
+ * Adds the Aggregate Root functionality to a base class.
5
+ * An aggregate root is an entity that represents a meaningful concept in the domain.
6
+ * It is the root of an aggregate, which is a cluster of domain objects that can be treated as a single unit.
7
+ *
8
+ * @template EventBase The base type of the events.
9
+ * @template TBase The base class type.
10
+ */
11
+ export function WithAggregateRoot(Base) {
12
+ var _a, _b;
13
+ class AggregateRoot extends Base {
14
+ constructor() {
15
+ super(...arguments);
16
+ this[_a] = false;
17
+ this[_b] = [];
18
+ }
19
+ set autoCommit(value) {
20
+ this[IS_AUTO_COMMIT_ENABLED] = value;
21
+ }
22
+ get autoCommit() {
23
+ return this[IS_AUTO_COMMIT_ENABLED];
24
+ }
25
+ publish(event) { }
26
+ publishAll(events) { }
27
+ commit() {
28
+ this.publishAll(this[INTERNAL_EVENTS]);
29
+ this[INTERNAL_EVENTS].length = 0;
30
+ }
31
+ uncommit() {
32
+ this[INTERNAL_EVENTS].length = 0;
33
+ }
34
+ getUncommittedEvents() {
35
+ return this[INTERNAL_EVENTS];
36
+ }
37
+ loadFromHistory(history) {
38
+ history.forEach((event) => this.apply(event, true));
39
+ }
40
+ apply(event, optionsOrIsFromHistory = {}) {
41
+ const isFromHistory = (typeof optionsOrIsFromHistory === 'boolean'
42
+ ? optionsOrIsFromHistory
43
+ : optionsOrIsFromHistory.fromHistory) ?? false;
44
+ const skipHandler = typeof optionsOrIsFromHistory === 'boolean'
45
+ ? false
46
+ : optionsOrIsFromHistory.skipHandler;
47
+ if (!isFromHistory && !this.autoCommit) {
48
+ this[INTERNAL_EVENTS].push(event);
49
+ }
50
+ this.autoCommit && this.publish(event);
51
+ if (!skipHandler) {
52
+ const handler = this.getEventHandler(event);
53
+ handler && handler.call(this, event);
54
+ }
55
+ }
56
+ getEventHandler(event) {
57
+ const handler = `on${this.getEventName(event)}`;
58
+ return this[handler];
59
+ }
60
+ getEventName(event) {
61
+ const { constructor } = Object.getPrototypeOf(event);
62
+ return constructor.name;
63
+ }
64
+ }
65
+ _a = IS_AUTO_COMMIT_ENABLED, _b = INTERNAL_EVENTS;
66
+ return AggregateRoot;
67
+ }
@@ -1 +1 @@
1
- export * from './of-type';
1
+ export * from './of-type.js';
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
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("./of-type"), exports);
1
+ export * from './of-type.js';
@@ -1,6 +1,6 @@
1
1
  import { Type } from '@nestjs/common';
2
2
  import { Observable } from 'rxjs';
3
- import { IEvent } from '../interfaces';
3
+ import { IEvent } from '../interfaces/index.js';
4
4
  /**
5
5
  * Filter values depending on their instance type (comparison is made
6
6
  * using native `instanceof`).
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ofType = ofType;
4
- const operators_1 = require("rxjs/operators");
1
+ import { filter } from 'rxjs/operators';
5
2
  /**
6
3
  * Filter values depending on their instance type (comparison is made
7
4
  * using native `instanceof`).
@@ -10,7 +7,7 @@ const operators_1 = require("rxjs/operators");
10
7
  *
11
8
  * @return A stream only emitting the filtered instances.
12
9
  */
13
- function ofType(...types) {
10
+ export function ofType(...types) {
14
11
  const isInstanceOf = (event) => !!types.find((classType) => event instanceof classType);
15
- return (source) => source.pipe((0, operators_1.filter)(isInstanceOf));
12
+ return (source) => source.pipe(filter(isInstanceOf));
16
13
  }
@@ -1,11 +1,11 @@
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 { Query } from './classes/query';
6
- import { CqrsModuleOptions, IQuery, IQueryBus, IQueryHandler, IQueryPublisher, IQueryResult } from './interfaces';
7
- import { AsyncContext } from './scopes';
8
- import { ObservableBus } from './utils/observable-bus';
5
+ import { Query } from './classes/query.js';
6
+ import { CqrsModuleOptions, IQuery, IQueryBus, IQueryHandler, IQueryPublisher, IQueryResult } from './interfaces/index.js';
7
+ import { AsyncContext } from './scopes/index.js';
8
+ import { ObservableBus } from './utils/observable-bus.js';
9
9
  export type QueryHandlerType<QueryBase extends IQuery = IQuery, QueryResultBase extends IQueryResult = IQueryResult> = Type<IQueryHandler<QueryBase, QueryResultBase>>;
10
10
  /**
11
11
  * @publicApi
package/dist/query-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,27 +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 QueryBus_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.QueryBus = void 0;
17
- const common_1 = require("@nestjs/common");
18
- const core_1 = require("@nestjs/core");
19
- require("reflect-metadata");
20
- const constants_1 = require("./constants");
21
- const constants_2 = require("./decorators/constants");
22
- const exceptions_1 = require("./exceptions");
23
- const invalid_query_handler_exception_1 = require("./exceptions/invalid-query-handler.exception");
24
- const default_query_pubsub_1 = require("./helpers/default-query-pubsub");
25
- const scopes_1 = require("./scopes");
26
- const observable_bus_1 = require("./utils/observable-bus");
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 { QUERY_HANDLER_METADATA, QUERY_METADATA, } from './decorators/constants.js';
19
+ import { QueryHandlerNotFoundException } from './exceptions/index.js';
20
+ import { InvalidQueryHandlerException } from './exceptions/invalid-query-handler.exception.js';
21
+ import { DefaultQueryPubSub } from './helpers/default-query-pubsub.js';
22
+ import { AsyncContext } from './scopes/index.js';
23
+ import { ObservableBus } from './utils/observable-bus.js';
27
24
  /**
28
25
  * @publicApi
29
26
  */
30
- let QueryBus = QueryBus_1 = class QueryBus extends observable_bus_1.ObservableBus {
27
+ let QueryBus = QueryBus_1 = class QueryBus extends ObservableBus {
31
28
  constructor(moduleRef, options) {
32
29
  super();
33
30
  this.moduleRef = moduleRef;
34
31
  this.options = options;
35
- this.logger = new common_1.Logger(QueryBus_1.name);
32
+ this.logger = new Logger(QueryBus_1.name);
36
33
  this.handlers = new Map();
37
34
  if (this.options?.queryPublisher) {
38
35
  this._publisher = this.options.queryPublisher;
@@ -64,7 +61,7 @@ let QueryBus = QueryBus_1 = class QueryBus extends observable_bus_1.ObservableBu
64
61
  const handler = this.handlers.get(queryId);
65
62
  if (!handler) {
66
63
  const queryName = this.getQueryName(query);
67
- throw new exceptions_1.QueryHandlerNotFoundException(queryName);
64
+ throw new QueryHandlerNotFoundException(queryName);
68
65
  }
69
66
  this._publisher.publish(query);
70
67
  return (await handler(query, asyncContext));
@@ -73,13 +70,13 @@ let QueryBus = QueryBus_1 = class QueryBus extends observable_bus_1.ObservableBu
73
70
  if (handler.isDependencyTreeStatic()) {
74
71
  const instance = handler.instance;
75
72
  if (!instance.execute) {
76
- throw new invalid_query_handler_exception_1.InvalidQueryHandlerException();
73
+ throw new InvalidQueryHandlerException();
77
74
  }
78
75
  this.handlers.set(queryId, (query) => instance.execute(query));
79
76
  return;
80
77
  }
81
78
  this.handlers.set(queryId, async (query, context) => {
82
- context ??= scopes_1.AsyncContext.of(query) ?? new scopes_1.AsyncContext();
79
+ context ??= AsyncContext.of(query) ?? new AsyncContext();
83
80
  this.moduleRef.registerRequestByContextId(context, context.id);
84
81
  const instance = await this.moduleRef.resolve(handler.metatype, context.id, {
85
82
  strict: false,
@@ -91,10 +88,10 @@ let QueryBus = QueryBus_1 = class QueryBus extends observable_bus_1.ObservableBu
91
88
  handlers.forEach((handler) => this.registerHandler(handler));
92
89
  }
93
90
  registerHandler(handler) {
94
- const typeRef = handler.metatype;
91
+ const typeRef = (handler.inject ? handler.instance?.constructor : handler.metatype);
95
92
  const target = this.reflectQueryId(typeRef);
96
93
  if (!target) {
97
- throw new invalid_query_handler_exception_1.InvalidQueryHandlerException();
94
+ throw new InvalidQueryHandlerException();
98
95
  }
99
96
  if (this.handlers.has(target)) {
100
97
  this.logger.warn(`Query handler [${typeRef.name}] is already registered. Overriding previously registered handler.`);
@@ -103,29 +100,29 @@ let QueryBus = QueryBus_1 = class QueryBus extends observable_bus_1.ObservableBu
103
100
  }
104
101
  getQueryId(query) {
105
102
  const { constructor: queryType } = Object.getPrototypeOf(query);
106
- const queryMetadata = Reflect.getMetadata(constants_2.QUERY_METADATA, queryType);
103
+ const queryMetadata = Reflect.getMetadata(QUERY_METADATA, queryType);
107
104
  if (!queryMetadata) {
108
- throw new exceptions_1.QueryHandlerNotFoundException(queryType.name);
105
+ throw new QueryHandlerNotFoundException(queryType.name);
109
106
  }
110
107
  return queryMetadata.id;
111
108
  }
112
109
  reflectQueryId(handler) {
113
- const query = Reflect.getMetadata(constants_2.QUERY_HANDLER_METADATA, handler);
114
- const queryMetadata = Reflect.getMetadata(constants_2.QUERY_METADATA, query);
110
+ const query = Reflect.getMetadata(QUERY_HANDLER_METADATA, handler);
111
+ const queryMetadata = Reflect.getMetadata(QUERY_METADATA, query);
115
112
  return queryMetadata.id;
116
113
  }
117
114
  useDefaultPublisher() {
118
- this._publisher = new default_query_pubsub_1.DefaultQueryPubSub(this.subject$);
115
+ this._publisher = new DefaultQueryPubSub(this.subject$);
119
116
  }
120
117
  getQueryName(query) {
121
118
  const { constructor } = Object.getPrototypeOf(query);
122
119
  return constructor.name;
123
120
  }
124
121
  };
125
- exports.QueryBus = QueryBus;
126
- exports.QueryBus = QueryBus = QueryBus_1 = __decorate([
127
- (0, common_1.Injectable)(),
128
- __param(1, (0, common_1.Optional)()),
129
- __param(1, (0, common_1.Inject)(constants_1.CQRS_MODULE_OPTIONS)),
130
- __metadata("design:paramtypes", [core_1.ModuleRef, Object])
122
+ QueryBus = QueryBus_1 = __decorate([
123
+ Injectable(),
124
+ __param(1, Optional()),
125
+ __param(1, Inject(CQRS_MODULE_OPTIONS)),
126
+ __metadata("design:paramtypes", [ModuleRef, Object])
131
127
  ], QueryBus);
128
+ export { QueryBus };
@@ -1,21 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AsyncContext = exports.ASYNC_CONTEXT_ATTRIBUTE = void 0;
4
- const core_1 = require("@nestjs/core");
5
- exports.ASYNC_CONTEXT_ATTRIBUTE = Symbol('ASYNC_CONTEXT_ATTRIBUTE');
1
+ import { ContextIdFactory } from '@nestjs/core';
2
+ export const ASYNC_CONTEXT_ATTRIBUTE = Symbol('ASYNC_CONTEXT_ATTRIBUTE');
6
3
  /**
7
4
  * Represents the context of an asynchronous operation.
8
5
  */
9
- class AsyncContext {
6
+ export class AsyncContext {
10
7
  constructor() {
11
- this.id = core_1.ContextIdFactory.create();
8
+ this.id = ContextIdFactory.create();
12
9
  }
13
10
  /**
14
11
  * Attaches the context to an object.
15
12
  * @param target The object to attach the context to.
16
13
  */
17
14
  attachTo(target) {
18
- Object.defineProperty(target, exports.ASYNC_CONTEXT_ATTRIBUTE, {
15
+ Object.defineProperty(target, ASYNC_CONTEXT_ATTRIBUTE, {
19
16
  value: this,
20
17
  enumerable: false,
21
18
  });
@@ -26,7 +23,7 @@ class AsyncContext {
26
23
  * @returns "true" if the target is attached to an async context, "false" otherwise.
27
24
  */
28
25
  static isAttached(target) {
29
- return !!target[exports.ASYNC_CONTEXT_ATTRIBUTE];
26
+ return !!target[ASYNC_CONTEXT_ATTRIBUTE];
30
27
  }
31
28
  /**
32
29
  * Merges the context of an asynchronous operation from a given command, query, or event to another object.
@@ -37,11 +34,11 @@ class AsyncContext {
37
34
  if (!from || !to) {
38
35
  return;
39
36
  }
40
- const fromContext = from[exports.ASYNC_CONTEXT_ATTRIBUTE];
37
+ const fromContext = from[ASYNC_CONTEXT_ATTRIBUTE];
41
38
  if (!fromContext) {
42
39
  return;
43
40
  }
44
- Object.defineProperty(to, exports.ASYNC_CONTEXT_ATTRIBUTE, {
41
+ Object.defineProperty(to, ASYNC_CONTEXT_ATTRIBUTE, {
45
42
  value: fromContext,
46
43
  enumerable: false,
47
44
  });
@@ -52,7 +49,6 @@ class AsyncContext {
52
49
  * @returns An "AsyncContext" instance or "undefined" if the context is not found.
53
50
  */
54
51
  static of(target) {
55
- return target[exports.ASYNC_CONTEXT_ATTRIBUTE];
52
+ return target[ASYNC_CONTEXT_ATTRIBUTE];
56
53
  }
57
54
  }
58
- exports.AsyncContext = AsyncContext;
@@ -1 +1 @@
1
- export * from './async.context';
1
+ export * from './async.context.js';
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
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("./async.context"), exports);
1
+ export * from './async.context.js';
@@ -1,8 +1,8 @@
1
- import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
2
- import { Module } from '@nestjs/core/injector/module';
3
- import { ModulesContainer } from '@nestjs/core/injector/modules-container';
4
- import { IEvent } from '../interfaces';
5
- import { ProvidersIntrospectionResult } from '../interfaces/providers-introspection-result.interface';
1
+ import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper.js';
2
+ import { Module } from '@nestjs/core/injector/module.js';
3
+ import { ModulesContainer } from '@nestjs/core/injector/modules-container.js';
4
+ import { IEvent } from '../interfaces/index.js';
5
+ import { ProvidersIntrospectionResult } from '../interfaces/providers-introspection-result.interface.js';
6
6
  export declare class ExplorerService<EventBase extends IEvent = IEvent> {
7
7
  private readonly modulesContainer;
8
8
  constructor(modulesContainer: ModulesContainer);
@@ -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);
@@ -8,21 +7,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
7
  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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ExplorerService = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const modules_container_1 = require("@nestjs/core/injector/modules-container");
15
- const constants_1 = require("../decorators/constants");
10
+ import { Injectable } from '@nestjs/common';
11
+ import { ModulesContainer } from '@nestjs/core/injector/modules-container.js';
12
+ import { COMMAND_HANDLER_METADATA, EVENTS_HANDLER_METADATA, QUERY_HANDLER_METADATA, SAGA_METADATA, } from '../decorators/constants.js';
16
13
  let ExplorerService = class ExplorerService {
17
14
  constructor(modulesContainer) {
18
15
  this.modulesContainer = modulesContainer;
19
16
  }
20
17
  explore() {
21
18
  const modules = [...this.modulesContainer.values()];
22
- const commands = this.flatMap(modules, (instance) => this.filterByMetadataKey(instance, constants_1.COMMAND_HANDLER_METADATA));
23
- const queries = this.flatMap(modules, (instance) => this.filterByMetadataKey(instance, constants_1.QUERY_HANDLER_METADATA));
24
- const events = this.flatMap(modules, (instance) => this.filterByMetadataKey(instance, constants_1.EVENTS_HANDLER_METADATA));
25
- const sagas = this.flatMap(modules, (instance) => this.filterByMetadataKey(instance, constants_1.SAGA_METADATA));
19
+ const commands = this.flatMap(modules, (instance) => this.filterByMetadataKey(instance, COMMAND_HANDLER_METADATA));
20
+ const queries = this.flatMap(modules, (instance) => this.filterByMetadataKey(instance, QUERY_HANDLER_METADATA));
21
+ const events = this.flatMap(modules, (instance) => this.filterByMetadataKey(instance, EVENTS_HANDLER_METADATA));
22
+ const sagas = this.flatMap(modules, (instance) => this.filterByMetadataKey(instance, SAGA_METADATA));
26
23
  return { commands, queries, events, sagas };
27
24
  }
28
25
  flatMap(modules, callback) {
@@ -32,22 +29,19 @@ let ExplorerService = class ExplorerService {
32
29
  return items.filter((item) => !!item);
33
30
  }
34
31
  filterByMetadataKey(wrapper, metadataKey) {
35
- const { instance } = wrapper;
36
- if (!instance) {
32
+ const clsRef = wrapper.instance?.constructor ?? wrapper.metatype;
33
+ if (!clsRef) {
37
34
  return;
38
35
  }
39
- if (!instance.constructor) {
40
- return;
41
- }
42
- const metadata = Reflect.getMetadata(metadataKey, instance.constructor);
36
+ const metadata = Reflect.getMetadata(metadataKey, clsRef);
43
37
  if (!metadata) {
44
38
  return;
45
39
  }
46
40
  return wrapper;
47
41
  }
48
42
  };
49
- exports.ExplorerService = ExplorerService;
50
- exports.ExplorerService = ExplorerService = __decorate([
51
- (0, common_1.Injectable)(),
52
- __metadata("design:paramtypes", [modules_container_1.ModulesContainer])
43
+ ExplorerService = __decorate([
44
+ Injectable(),
45
+ __metadata("design:paramtypes", [ModulesContainer])
53
46
  ], ExplorerService);
47
+ export { ExplorerService };
@@ -1,8 +1,8 @@
1
1
  import { Type } from '@nestjs/common';
2
- import { AggregateRoot } from '../aggregate-root';
3
- import { EventBus } from '../event-bus';
2
+ import { IAggregateRoot } from '../interfaces/index.js';
3
+ import { EventBus } from '../event-bus.js';
4
4
  export declare class AggregateRootStorage {
5
5
  private static storage;
6
- static add(type: Type<AggregateRoot>): void;
6
+ static add(type: Type<IAggregateRoot>): void;
7
7
  static mergeContext(eventBus: EventBus): void;
8
8
  }
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AggregateRootStorage = void 0;
4
- class AggregateRootStorage {
1
+ export class AggregateRootStorage {
5
2
  static add(type) {
6
3
  this.storage.push(type);
7
4
  }
@@ -17,5 +14,4 @@ class AggregateRootStorage {
17
14
  this.storage = [];
18
15
  }
19
16
  }
20
- exports.AggregateRootStorage = AggregateRootStorage;
21
17
  AggregateRootStorage.storage = [];
@@ -1,8 +1,8 @@
1
1
  import { Type } from '@nestjs/common';
2
2
  import 'reflect-metadata';
3
3
  import { Observable } from 'rxjs';
4
- import { CqrsModuleOptions, ICommand, IEvent, IUnhandledExceptionPublisher, UnhandledExceptionInfo } from './interfaces';
5
- import { ObservableBus } from './utils/observable-bus';
4
+ import { CqrsModuleOptions, ICommand, IEvent, IUnhandledExceptionPublisher, UnhandledExceptionInfo } from './interfaces/index.js';
5
+ import { ObservableBus } from './utils/observable-bus.js';
6
6
  /**
7
7
  * A bus that publishes unhandled exceptions.
8
8
  * @template Cause The type of the cause of the exception.
@@ -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);
@@ -11,19 +10,17 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
10
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
11
  return function (target, key) { decorator(target, key, paramIndex); }
13
12
  };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.UnhandledExceptionBus = void 0;
16
- const common_1 = require("@nestjs/common");
17
- require("reflect-metadata");
18
- const rxjs_1 = require("rxjs");
19
- const constants_1 = require("./constants");
20
- const default_unhandled_exception_pubsub_1 = require("./helpers/default-unhandled-exception-pubsub");
21
- const observable_bus_1 = require("./utils/observable-bus");
13
+ import { Inject, Injectable, Optional } from '@nestjs/common';
14
+ import 'reflect-metadata';
15
+ import { filter } from 'rxjs';
16
+ import { CQRS_MODULE_OPTIONS } from './constants.js';
17
+ import { DefaultUnhandledExceptionPubSub } from './helpers/default-unhandled-exception-pubsub.js';
18
+ import { ObservableBus } from './utils/observable-bus.js';
22
19
  /**
23
20
  * A bus that publishes unhandled exceptions.
24
21
  * @template Cause The type of the cause of the exception.
25
22
  */
26
- let UnhandledExceptionBus = class UnhandledExceptionBus extends observable_bus_1.ObservableBus {
23
+ let UnhandledExceptionBus = class UnhandledExceptionBus extends ObservableBus {
27
24
  constructor(options) {
28
25
  super();
29
26
  this.options = options;
@@ -44,7 +41,7 @@ let UnhandledExceptionBus = class UnhandledExceptionBus extends observable_bus_1
44
41
  */
45
42
  static ofType(...types) {
46
43
  const isInstanceOf = (exceptionInfo) => !!types.find((classType) => exceptionInfo.exception instanceof classType);
47
- return (source) => source.pipe((0, rxjs_1.filter)(isInstanceOf));
44
+ return (source) => source.pipe(filter(isInstanceOf));
48
45
  }
49
46
  /**
50
47
  * Gets the publisher of the bus.
@@ -66,13 +63,13 @@ let UnhandledExceptionBus = class UnhandledExceptionBus extends observable_bus_1
66
63
  return this._publisher.publish(info);
67
64
  }
68
65
  useDefaultPublisher() {
69
- this._publisher = new default_unhandled_exception_pubsub_1.DefaultUnhandledExceptionPubSub(this.subject$);
66
+ this._publisher = new DefaultUnhandledExceptionPubSub(this.subject$);
70
67
  }
71
68
  };
72
- exports.UnhandledExceptionBus = UnhandledExceptionBus;
73
- exports.UnhandledExceptionBus = UnhandledExceptionBus = __decorate([
74
- (0, common_1.Injectable)(),
75
- __param(0, (0, common_1.Optional)()),
76
- __param(0, (0, common_1.Inject)(constants_1.CQRS_MODULE_OPTIONS)),
69
+ UnhandledExceptionBus = __decorate([
70
+ Injectable(),
71
+ __param(0, Optional()),
72
+ __param(0, Inject(CQRS_MODULE_OPTIONS)),
77
73
  __metadata("design:paramtypes", [Object])
78
74
  ], UnhandledExceptionBus);
75
+ export { UnhandledExceptionBus };
@@ -1 +1 @@
1
- export * from './observable-bus';
1
+ export * from './observable-bus.js';
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
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("./observable-bus"), exports);
1
+ export * from './observable-bus.js';
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ObservableBus = void 0;
4
- const rxjs_1 = require("rxjs");
5
- class ObservableBus extends rxjs_1.Observable {
1
+ import { Observable, Subject } from 'rxjs';
2
+ export class ObservableBus extends Observable {
6
3
  constructor() {
7
4
  super();
8
- this._subject$ = new rxjs_1.Subject();
5
+ this._subject$ = new Subject();
9
6
  this.source = this._subject$;
10
7
  }
11
8
  get subject$() {
12
9
  return this._subject$;
13
10
  }
14
11
  }
15
- exports.ObservableBus = ObservableBus;