@rolandsall24/nest-mediator 0.6.0 → 0.7.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 (73) hide show
  1. package/README.md +354 -56
  2. package/dist/lib/decorators/event-criticality.decorator.d.ts +61 -0
  3. package/dist/lib/decorators/event-criticality.decorator.d.ts.map +1 -0
  4. package/dist/lib/decorators/event-criticality.decorator.js +71 -0
  5. package/dist/lib/decorators/event-criticality.decorator.js.map +1 -0
  6. package/dist/lib/decorators/event-handler.decorator.d.ts +21 -0
  7. package/dist/lib/decorators/event-handler.decorator.d.ts.map +1 -0
  8. package/dist/lib/decorators/event-handler.decorator.js +27 -0
  9. package/dist/lib/decorators/event-handler.decorator.js.map +1 -0
  10. package/dist/lib/decorators/index.d.ts +2 -0
  11. package/dist/lib/decorators/index.d.ts.map +1 -1
  12. package/dist/lib/decorators/index.js +2 -0
  13. package/dist/lib/decorators/index.js.map +1 -1
  14. package/dist/lib/interfaces/command-bus.interface.d.ts +25 -0
  15. package/dist/lib/interfaces/command-bus.interface.d.ts.map +1 -0
  16. package/dist/lib/interfaces/command-bus.interface.js +3 -0
  17. package/dist/lib/interfaces/command-bus.interface.js.map +1 -0
  18. package/dist/lib/interfaces/event-bus.interface.d.ts +35 -0
  19. package/dist/lib/interfaces/event-bus.interface.d.ts.map +1 -0
  20. package/dist/lib/interfaces/event-bus.interface.js +3 -0
  21. package/dist/lib/interfaces/event-bus.interface.js.map +1 -0
  22. package/dist/lib/interfaces/event-consumer.interface.d.ts +64 -0
  23. package/dist/lib/interfaces/event-consumer.interface.d.ts.map +1 -0
  24. package/dist/lib/interfaces/event-consumer.interface.js +3 -0
  25. package/dist/lib/interfaces/event-consumer.interface.js.map +1 -0
  26. package/dist/lib/interfaces/event-criticality.interface.d.ts +28 -0
  27. package/dist/lib/interfaces/event-criticality.interface.d.ts.map +1 -0
  28. package/dist/lib/interfaces/event-criticality.interface.js +25 -0
  29. package/dist/lib/interfaces/event-criticality.interface.js.map +1 -0
  30. package/dist/lib/interfaces/event-handler.interface.d.ts +24 -0
  31. package/dist/lib/interfaces/event-handler.interface.d.ts.map +1 -0
  32. package/dist/lib/interfaces/event-handler.interface.js +3 -0
  33. package/dist/lib/interfaces/event-handler.interface.js.map +1 -0
  34. package/dist/lib/interfaces/event.interface.d.ts +30 -0
  35. package/dist/lib/interfaces/event.interface.d.ts.map +1 -0
  36. package/dist/lib/interfaces/event.interface.js +3 -0
  37. package/dist/lib/interfaces/event.interface.js.map +1 -0
  38. package/dist/lib/interfaces/index.d.ts +7 -0
  39. package/dist/lib/interfaces/index.d.ts.map +1 -1
  40. package/dist/lib/interfaces/index.js +7 -0
  41. package/dist/lib/interfaces/index.js.map +1 -1
  42. package/dist/lib/interfaces/mediator.interface.d.ts +14 -0
  43. package/dist/lib/interfaces/mediator.interface.d.ts.map +1 -0
  44. package/dist/lib/interfaces/mediator.interface.js +3 -0
  45. package/dist/lib/interfaces/mediator.interface.js.map +1 -0
  46. package/dist/lib/interfaces/query-bus.interface.d.ts +26 -0
  47. package/dist/lib/interfaces/query-bus.interface.d.ts.map +1 -0
  48. package/dist/lib/interfaces/query-bus.interface.js +3 -0
  49. package/dist/lib/interfaces/query-bus.interface.js.map +1 -0
  50. package/dist/lib/nest-mediator.module.d.ts.map +1 -1
  51. package/dist/lib/nest-mediator.module.js +19 -0
  52. package/dist/lib/nest-mediator.module.js.map +1 -1
  53. package/dist/lib/services/command.bus.d.ts +30 -0
  54. package/dist/lib/services/command.bus.d.ts.map +1 -0
  55. package/dist/lib/services/command.bus.js +69 -0
  56. package/dist/lib/services/command.bus.js.map +1 -0
  57. package/dist/lib/services/event.bus.d.ts +61 -0
  58. package/dist/lib/services/event.bus.d.ts.map +1 -0
  59. package/dist/lib/services/event.bus.js +176 -0
  60. package/dist/lib/services/event.bus.js.map +1 -0
  61. package/dist/lib/services/mediator.bus.d.ts +48 -30
  62. package/dist/lib/services/mediator.bus.d.ts.map +1 -1
  63. package/dist/lib/services/mediator.bus.js +58 -101
  64. package/dist/lib/services/mediator.bus.js.map +1 -1
  65. package/dist/lib/services/pipeline.orchestrator.d.ts +46 -0
  66. package/dist/lib/services/pipeline.orchestrator.d.ts.map +1 -0
  67. package/dist/lib/services/pipeline.orchestrator.js +87 -0
  68. package/dist/lib/services/pipeline.orchestrator.js.map +1 -0
  69. package/dist/lib/services/query.bus.d.ts +31 -0
  70. package/dist/lib/services/query.bus.d.ts.map +1 -0
  71. package/dist/lib/services/query.bus.js +68 -0
  72. package/dist/lib/services/query.bus.js.map +1 -0
  73. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C;AAC/C,+DAA6C;AAC7C,mEAAiD;AACjD,+DAA6C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C;AAC/C,+DAA6C;AAC7C,mEAAiD;AACjD,+DAA6C;AAC7C,+DAA6C;AAC7C,mEAAiD"}
@@ -0,0 +1,25 @@
1
+ import { Type } from '@nestjs/common';
2
+ import { ICommand } from './command.interface.js';
3
+ import { ICommandHandler } from './command-handler.interface.js';
4
+ /**
5
+ * Interface for the command bus.
6
+ * Responsible for dispatching commands to their handlers.
7
+ */
8
+ export interface ICommandBus {
9
+ /**
10
+ * Send a command to its handler
11
+ * @param command - The command instance
12
+ */
13
+ send<TCommand extends ICommand>(command: TCommand): Promise<void>;
14
+ /**
15
+ * Register a command handler
16
+ * @param command - The command class
17
+ * @param handler - The handler class
18
+ */
19
+ registerCommandHandler(command: Type<ICommand>, handler: Type<ICommandHandler<any>>): void;
20
+ /**
21
+ * Get registered command names (for debugging)
22
+ */
23
+ getRegisteredCommands(): string[];
24
+ }
25
+ //# sourceMappingURL=command-bus.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-bus.interface.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/command-bus.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,IAAI,CAAC,QAAQ,SAAS,QAAQ,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElE;;;;OAIG;IACH,sBAAsB,CACpB,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,EACvB,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,GAClC,IAAI,CAAC;IAER;;OAEG;IACH,qBAAqB,IAAI,MAAM,EAAE,CAAC;CACnC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=command-bus.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-bus.interface.js","sourceRoot":"","sources":["../../../src/lib/interfaces/command-bus.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import { Type } from '@nestjs/common';
2
+ import { IEvent, EventPublishResult } from './event.interface.js';
3
+ import { IEventConsumer } from './event-consumer.interface.js';
4
+ import { EventCriticalityMetadata } from './event-criticality.interface.js';
5
+ /**
6
+ * Interface for the event bus.
7
+ * Responsible for publishing events to their consumers.
8
+ */
9
+ export interface IEventBus {
10
+ /**
11
+ * Publish an event to all its consumers
12
+ * @param event - The event instance
13
+ * @returns Promise with the publish result
14
+ */
15
+ publish<TEvent extends IEvent>(event: TEvent): Promise<EventPublishResult>;
16
+ /**
17
+ * Register an event consumer
18
+ * @param event - The event class
19
+ * @param handler - The consumer class
20
+ * @param criticalityMetadata - Criticality metadata
21
+ */
22
+ registerEventHandler(event: Type<IEvent>, handler: Type<IEventConsumer<any>>, criticalityMetadata?: EventCriticalityMetadata): void;
23
+ /**
24
+ * Get registered events and their consumers (for debugging)
25
+ */
26
+ getRegisteredEvents(): {
27
+ event: string;
28
+ handlers: {
29
+ name: string;
30
+ criticality: string;
31
+ order: number;
32
+ }[];
33
+ }[];
34
+ }
35
+ //# sourceMappingURL=event-bus.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus.interface.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/event-bus.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAE5E;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,OAAO,CAAC,MAAM,SAAS,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAE3E;;;;;OAKG;IACH,oBAAoB,CAClB,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EACnB,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,EAClC,mBAAmB,CAAC,EAAE,wBAAwB,GAC7C,IAAI,CAAC;IAER;;OAEG;IACH,mBAAmB,IAAI;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;KAClE,EAAE,CAAC;CACL"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=event-bus.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus.interface.js","sourceRoot":"","sources":["../../../src/lib/interfaces/event-bus.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,64 @@
1
+ import { IEvent } from './event.interface.js';
2
+ /**
3
+ * Interface for event consumers.
4
+ * Event consumers subscribe to events and react to them.
5
+ * Multiple consumers can subscribe to the same event.
6
+ *
7
+ * Use this interface for non-critical consumers (fire-and-forget).
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * @EventHandler(UserCreatedEvent)
12
+ * @NonCritical()
13
+ * export class SendWelcomeEmailConsumer implements IEventConsumer<UserCreatedEvent> {
14
+ * async handle(event: UserCreatedEvent): Promise<void> {
15
+ * await this.emailService.sendWelcome(event.userEmail);
16
+ * }
17
+ * }
18
+ * ```
19
+ */
20
+ export interface IEventConsumer<TEvent extends IEvent> {
21
+ /**
22
+ * Handle the event
23
+ * @param event - The event instance
24
+ */
25
+ handle(event: TEvent): Promise<void>;
26
+ }
27
+ /**
28
+ * Interface for critical event consumers with optional compensation.
29
+ * Critical consumers run sequentially and can define a compensate method
30
+ * that will be called if a subsequent critical consumer fails.
31
+ *
32
+ * Compensation is called in reverse order (last succeeded -> first succeeded)
33
+ * when a critical consumer in the chain fails.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * @EventHandler(OrderPlacedEvent)
38
+ * @Critical({ order: 2 })
39
+ * export class ReserveInventoryConsumer implements ICriticalEventConsumer<OrderPlacedEvent> {
40
+ * async handle(event: OrderPlacedEvent): Promise<void> {
41
+ * await this.inventoryService.reserve(event.orderId, event.items);
42
+ * }
43
+ *
44
+ * async compensate(event: OrderPlacedEvent): Promise<void> {
45
+ * await this.inventoryService.releaseByOrderId(event.orderId);
46
+ * }
47
+ * }
48
+ * ```
49
+ */
50
+ export interface ICriticalEventConsumer<TEvent extends IEvent> extends IEventConsumer<TEvent> {
51
+ /**
52
+ * Compensate/rollback the work done by handle().
53
+ * Called when a subsequent critical consumer fails.
54
+ * Should be idempotent and derive state from the event.
55
+ *
56
+ * @param event - The same event instance passed to handle()
57
+ */
58
+ compensate?(event: TEvent): Promise<void>;
59
+ }
60
+ /**
61
+ * @deprecated Use IEventConsumer instead
62
+ */
63
+ export type IEventHandler<TEvent extends IEvent> = IEventConsumer<TEvent>;
64
+ //# sourceMappingURL=event-consumer.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-consumer.interface.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/event-consumer.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,cAAc,CAAC,MAAM,SAAS,MAAM;IACnD;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,sBAAsB,CAAC,MAAM,SAAS,MAAM,CAAE,SAAQ,cAAc,CAAC,MAAM,CAAC;IAC3F;;;;;;OAMG;IACH,UAAU,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=event-consumer.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-consumer.interface.js","sourceRoot":"","sources":["../../../src/lib/interfaces/event-consumer.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Criticality level for event consumers.
3
+ * Determines how the consumer is executed when an event is published.
4
+ */
5
+ export declare enum EventCriticality {
6
+ /**
7
+ * Critical consumers run sequentially in order.
8
+ * - Must complete before non-critical consumers start
9
+ * - If one fails, the publish operation fails
10
+ * - Are awaited by the caller
11
+ */
12
+ CRITICAL = "critical",
13
+ /**
14
+ * Non-critical consumers run in parallel after critical consumers complete.
15
+ * - Fire and forget (not awaited by the caller)
16
+ * - Failures are logged but don't affect the publish result
17
+ * - Don't block the caller
18
+ */
19
+ NON_CRITICAL = "non-critical"
20
+ }
21
+ /**
22
+ * Metadata stored for event consumer criticality
23
+ */
24
+ export interface EventCriticalityMetadata {
25
+ criticality: EventCriticality;
26
+ order: number;
27
+ }
28
+ //# sourceMappingURL=event-criticality.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-criticality.interface.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/event-criticality.interface.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,gBAAgB;IAC1B;;;;;OAKG;IACH,QAAQ,aAAa;IAErB;;;;;OAKG;IACH,YAAY,iBAAiB;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,gBAAgB,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventCriticality = void 0;
4
+ /**
5
+ * Criticality level for event consumers.
6
+ * Determines how the consumer is executed when an event is published.
7
+ */
8
+ var EventCriticality;
9
+ (function (EventCriticality) {
10
+ /**
11
+ * Critical consumers run sequentially in order.
12
+ * - Must complete before non-critical consumers start
13
+ * - If one fails, the publish operation fails
14
+ * - Are awaited by the caller
15
+ */
16
+ EventCriticality["CRITICAL"] = "critical";
17
+ /**
18
+ * Non-critical consumers run in parallel after critical consumers complete.
19
+ * - Fire and forget (not awaited by the caller)
20
+ * - Failures are logged but don't affect the publish result
21
+ * - Don't block the caller
22
+ */
23
+ EventCriticality["NON_CRITICAL"] = "non-critical";
24
+ })(EventCriticality || (exports.EventCriticality = EventCriticality = {}));
25
+ //# sourceMappingURL=event-criticality.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-criticality.interface.js","sourceRoot":"","sources":["../../../src/lib/interfaces/event-criticality.interface.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,IAAY,gBAgBX;AAhBD,WAAY,gBAAgB;IAC1B;;;;;OAKG;IACH,yCAAqB,CAAA;IAErB;;;;;OAKG;IACH,iDAA6B,CAAA;AAC/B,CAAC,EAhBW,gBAAgB,gCAAhB,gBAAgB,QAgB3B"}
@@ -0,0 +1,24 @@
1
+ import { IEvent } from './event.interface.js';
2
+ /**
3
+ * Interface for event handlers
4
+ * Event handlers subscribe to events and react to them.
5
+ * Multiple handlers can subscribe to the same event.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * @EventHandler(UserCreatedEvent)
10
+ * export class SendWelcomeEmailHandler implements IEventHandler<UserCreatedEvent> {
11
+ * async handle(event: UserCreatedEvent): Promise<void> {
12
+ * await this.emailService.sendWelcome(event.userEmail);
13
+ * }
14
+ * }
15
+ * ```
16
+ */
17
+ export interface IEventHandler<TEvent extends IEvent> {
18
+ /**
19
+ * Handle the event
20
+ * @param event - The event instance
21
+ */
22
+ handle(event: TEvent): Promise<void>;
23
+ }
24
+ //# sourceMappingURL=event-handler.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-handler.interface.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/event-handler.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM,SAAS,MAAM;IAClD;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=event-handler.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-handler.interface.js","sourceRoot":"","sources":["../../../src/lib/interfaces/event-handler.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Marker interface for events
3
+ * Events represent something that has happened in the domain.
4
+ * Multiple handlers can subscribe to the same event.
5
+ */
6
+ export interface IEvent {
7
+ }
8
+ /**
9
+ * Result of publishing an event
10
+ */
11
+ export interface EventPublishResult {
12
+ /**
13
+ * Total number of handlers that were invoked
14
+ */
15
+ totalHandlers: number;
16
+ /**
17
+ * Number of critical handlers that executed successfully
18
+ */
19
+ criticalSucceeded: number;
20
+ /**
21
+ * Number of non-critical handlers that were dispatched
22
+ * Note: Non-critical handlers run in background, so this only indicates they were started
23
+ */
24
+ nonCriticalDispatched: number;
25
+ /**
26
+ * Number of compensations that were executed (only non-zero when a critical handler fails)
27
+ */
28
+ compensationsRun: number;
29
+ }
30
+ //# sourceMappingURL=event.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.interface.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/event.interface.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,MAAM;CAAG;AAE1B;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=event.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.interface.js","sourceRoot":"","sources":["../../../src/lib/interfaces/event.interface.ts"],"names":[],"mappings":""}
@@ -3,4 +3,11 @@ export * from './query.interface.js';
3
3
  export * from './command-handler.interface.js';
4
4
  export * from './query-handler.interface.js';
5
5
  export * from './pipeline-behavior.interface.js';
6
+ export * from './event.interface.js';
7
+ export * from './event-consumer.interface.js';
8
+ export * from './event-criticality.interface.js';
9
+ export * from './command-bus.interface.js';
10
+ export * from './query-bus.interface.js';
11
+ export * from './event-bus.interface.js';
12
+ export * from './mediator.interface.js';
6
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC"}
@@ -19,4 +19,11 @@ __exportStar(require("./query.interface.js"), exports);
19
19
  __exportStar(require("./command-handler.interface.js"), exports);
20
20
  __exportStar(require("./query-handler.interface.js"), exports);
21
21
  __exportStar(require("./pipeline-behavior.interface.js"), exports);
22
+ __exportStar(require("./event.interface.js"), exports);
23
+ __exportStar(require("./event-consumer.interface.js"), exports);
24
+ __exportStar(require("./event-criticality.interface.js"), exports);
25
+ __exportStar(require("./command-bus.interface.js"), exports);
26
+ __exportStar(require("./query-bus.interface.js"), exports);
27
+ __exportStar(require("./event-bus.interface.js"), exports);
28
+ __exportStar(require("./mediator.interface.js"), exports);
22
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,uDAAqC;AACrC,iEAA+C;AAC/C,+DAA6C;AAC7C,mEAAiD"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,uDAAqC;AACrC,iEAA+C;AAC/C,+DAA6C;AAC7C,mEAAiD;AACjD,uDAAqC;AACrC,gEAA8C;AAC9C,mEAAiD;AACjD,6DAA2C;AAC3C,2DAAyC;AACzC,2DAAyC;AACzC,0DAAwC"}
@@ -0,0 +1,14 @@
1
+ import { ICommandBus } from './command-bus.interface.js';
2
+ import { IQueryBus } from './query-bus.interface.js';
3
+ import { IEventBus } from './event-bus.interface.js';
4
+ /**
5
+ * Unified mediator interface combining command, query, and event bus capabilities.
6
+ * This is the primary interface clients should depend on.
7
+ */
8
+ export interface IMediator extends ICommandBus, IQueryBus, IEventBus {
9
+ /**
10
+ * Get registered behavior names (for debugging)
11
+ */
12
+ getRegisteredBehaviors(): string[];
13
+ }
14
+ //# sourceMappingURL=mediator.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mediator.interface.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/mediator.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,WAAW,EAAE,SAAS,EAAE,SAAS;IAClE;;OAEG;IACH,sBAAsB,IAAI,MAAM,EAAE,CAAC;CACpC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=mediator.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mediator.interface.js","sourceRoot":"","sources":["../../../src/lib/interfaces/mediator.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { Type } from '@nestjs/common';
2
+ import { IQuery } from './query.interface.js';
3
+ import { IQueryHandler } from './query-handler.interface.js';
4
+ /**
5
+ * Interface for the query bus.
6
+ * Responsible for dispatching queries to their handlers.
7
+ */
8
+ export interface IQueryBus {
9
+ /**
10
+ * Execute a query through its handler
11
+ * @param query - The query instance
12
+ * @returns Promise with the result
13
+ */
14
+ query<TQuery extends IQuery, TResult = any>(query: TQuery): Promise<TResult>;
15
+ /**
16
+ * Register a query handler
17
+ * @param query - The query class
18
+ * @param handler - The handler class
19
+ */
20
+ registerQueryHandler(query: Type<IQuery>, handler: Type<IQueryHandler<any, any>>): void;
21
+ /**
22
+ * Get registered query names (for debugging)
23
+ */
24
+ getRegisteredQueries(): string[];
25
+ }
26
+ //# sourceMappingURL=query-bus.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-bus.interface.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/query-bus.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,KAAK,CAAC,MAAM,SAAS,MAAM,EAAE,OAAO,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7E;;;;OAIG;IACH,oBAAoB,CAClB,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EACnB,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GACrC,IAAI,CAAC;IAER;;OAEG;IACH,oBAAoB,IAAI,MAAM,EAAE,CAAC;CAClC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=query-bus.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-bus.interface.js","sourceRoot":"","sources":["../../../src/lib/interfaces/query-bus.interface.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"nest-mediator.module.d.ts","sourceRoot":"","sources":["../../src/lib/nest-mediator.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAmB,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAqBlD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IAEpC;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAE7D,qBACa,kBAAmB,YAAW,YAAY;IAEnD,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBAFhB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,gBAAgB;IAGrD,YAAY;IA6FZ;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,yBAA8B,GAAG,aAAa;CAoCvE"}
1
+ {"version":3,"file":"nest-mediator.module.d.ts","sourceRoot":"","sources":["../../src/lib/nest-mediator.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAmB,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AA8BlD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IAEpC;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAE7D,qBACa,kBAAmB,YAAW,YAAY;IAEnD,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBAFhB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,gBAAgB;IAGrD,YAAY;IAwHZ;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,yBAA8B,GAAG,aAAa;CAwCvE"}
@@ -14,6 +14,10 @@ exports.NestMediatorModule = exports.NEST_MEDIATOR_OPTIONS = void 0;
14
14
  const common_1 = require("@nestjs/common");
15
15
  const core_1 = require("@nestjs/core");
16
16
  const index_js_1 = require("./services/index.js");
17
+ const command_bus_js_1 = require("./services/command.bus.js");
18
+ const query_bus_js_1 = require("./services/query.bus.js");
19
+ const event_bus_js_1 = require("./services/event.bus.js");
20
+ const pipeline_orchestrator_js_1 = require("./services/pipeline.orchestrator.js");
17
21
  const index_js_2 = require("./decorators/index.js");
18
22
  const index_js_3 = require("./behaviors/index.js");
19
23
  /**
@@ -72,6 +76,17 @@ let NestMediatorModule = NestMediatorModule_1 = class NestMediatorModule {
72
76
  console.log(`[NestMediator] Registering pipeline behavior: ${handlerType.name} (priority: ${behaviorMetadata.priority ?? 0}, scope: ${behaviorMetadata.scope ?? 'all'}${requestTypeInfo})`);
73
77
  this.mediatorBus.registerPipelineBehavior(handlerType, behaviorMetadata, requestType);
74
78
  }
79
+ // Register event handlers
80
+ const eventMetadata = this.reflector.get(index_js_2.EVENT_HANDLER_METADATA, handlerType);
81
+ if (eventMetadata) {
82
+ // Get criticality metadata (if any)
83
+ const criticalityMetadata = this.reflector.get(index_js_2.EVENT_CRITICALITY_METADATA, handlerType);
84
+ const criticalityInfo = criticalityMetadata
85
+ ? ` (criticality: ${criticalityMetadata.criticality}, order: ${criticalityMetadata.order})`
86
+ : ' (criticality: non-critical)';
87
+ console.log(`[NestMediator] Registering event handler: ${handlerType.name} for event: ${eventMetadata.name}${criticalityInfo}`);
88
+ this.mediatorBus.registerEventHandler(eventMetadata, handlerType, criticalityMetadata);
89
+ }
75
90
  }
76
91
  }
77
92
  /**
@@ -115,6 +130,10 @@ let NestMediatorModule = NestMediatorModule_1 = class NestMediatorModule {
115
130
  module: NestMediatorModule_1,
116
131
  imports: [core_1.DiscoveryModule],
117
132
  providers: [
133
+ pipeline_orchestrator_js_1.PipelineOrchestrator,
134
+ command_bus_js_1.CommandBus,
135
+ query_bus_js_1.QueryBus,
136
+ event_bus_js_1.EventBus,
118
137
  index_js_1.MediatorBus,
119
138
  core_1.Reflector,
120
139
  ...builtInProviders,
@@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,CAAC;QAC7C,CAAC;QAED,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC7B,gBAAgB,CAAC,IAAI,CAAC,6BAAkB,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO;YACL,MAAM,EAAE,oBAAkB;YAC1B,OAAO,EAAE,CAAC,sBAAe,CAAC;YAC1B,SAAS,EAAE;gBACT,+CAAoB;gBACpB,2BAAU;gBACV,uBAAQ;gBACR,uBAAQ;gBACR,sBAAW;gBACX,gBAAS;gBACT,GAAG,gBAAgB;gBACnB;oBACE,OAAO,EAAE,6BAAqB;oBAC9B,QAAQ,EAAE,OAAO;iBAClB;aACF;YACD,OAAO,EAAE,CAAC,sBAAW,CAAC;YACtB,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;CACF,CAAA;AA7LY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,eAAM,EAAC,EAAE,CAAC;qCAGuB,sBAAW;QACb,gBAAS;QACF,uBAAgB;GAJ1C,kBAAkB,CA6L9B"}
@@ -0,0 +1,30 @@
1
+ import { Type } from '@nestjs/common';
2
+ import { ModuleRef } from '@nestjs/core';
3
+ import { ICommand, ICommandHandler, ICommandBus } from '../interfaces/index.js';
4
+ import { PipelineOrchestrator } from './pipeline.orchestrator.js';
5
+ /**
6
+ * Command bus implementation.
7
+ * Dispatches commands to their handlers through the pipeline.
8
+ */
9
+ export declare class CommandBus implements ICommandBus {
10
+ private readonly moduleRef;
11
+ private readonly pipelineOrchestrator;
12
+ private readonly handlers;
13
+ constructor(moduleRef: ModuleRef, pipelineOrchestrator: PipelineOrchestrator);
14
+ /**
15
+ * Send a command to its handler through the pipeline
16
+ * @param command - The command instance
17
+ */
18
+ send<TCommand extends ICommand>(command: TCommand): Promise<void>;
19
+ /**
20
+ * Register a command handler
21
+ * @param command - The command class
22
+ * @param handler - The handler class
23
+ */
24
+ registerCommandHandler(command: Type<ICommand>, handler: Type<ICommandHandler<any>>): void;
25
+ /**
26
+ * Get registered command names (for debugging)
27
+ */
28
+ getRegisteredCommands(): string[];
29
+ }
30
+ //# sourceMappingURL=command.bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.bus.d.ts","sourceRoot":"","sources":["../../../src/lib/services/command.bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE;;;GAGG;AACH,qBACa,UAAW,YAAW,WAAW;IAI1C,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAJvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiD;gBAGvD,SAAS,EAAE,SAAS,EACpB,oBAAoB,EAAE,oBAAoB;IAG7D;;;OAGG;IACG,IAAI,CAAC,QAAQ,SAAS,QAAQ,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBvE;;;;OAIG;IACH,sBAAsB,CACpB,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,EACvB,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,GAClC,IAAI;IAUP;;OAEG;IACH,qBAAqB,IAAI,MAAM,EAAE;CAGlC"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CommandBus = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const core_1 = require("@nestjs/core");
15
+ const handler_not_found_exception_js_1 = require("../exceptions/handler-not-found.exception.js");
16
+ const pipeline_orchestrator_js_1 = require("./pipeline.orchestrator.js");
17
+ /**
18
+ * Command bus implementation.
19
+ * Dispatches commands to their handlers through the pipeline.
20
+ */
21
+ let CommandBus = class CommandBus {
22
+ constructor(moduleRef, pipelineOrchestrator) {
23
+ this.moduleRef = moduleRef;
24
+ this.pipelineOrchestrator = pipelineOrchestrator;
25
+ this.handlers = new Map();
26
+ }
27
+ /**
28
+ * Send a command to its handler through the pipeline
29
+ * @param command - The command instance
30
+ */
31
+ async send(command) {
32
+ const commandName = command.constructor.name;
33
+ const handlerType = this.handlers.get(commandName);
34
+ if (!handlerType) {
35
+ throw new handler_not_found_exception_js_1.HandlerNotFoundException(commandName, 'command');
36
+ }
37
+ const handler = this.moduleRef.get(handlerType, {
38
+ strict: false,
39
+ });
40
+ // Build and execute pipeline
41
+ const pipeline = this.pipelineOrchestrator.buildPipeline(command, 'command', () => handler.execute(command));
42
+ await pipeline();
43
+ }
44
+ /**
45
+ * Register a command handler
46
+ * @param command - The command class
47
+ * @param handler - The handler class
48
+ */
49
+ registerCommandHandler(command, handler) {
50
+ const commandName = command.name;
51
+ if (this.handlers.has(commandName)) {
52
+ throw new Error(`Command handler for ${commandName} is already registered`);
53
+ }
54
+ this.handlers.set(commandName, handler);
55
+ }
56
+ /**
57
+ * Get registered command names (for debugging)
58
+ */
59
+ getRegisteredCommands() {
60
+ return Array.from(this.handlers.keys());
61
+ }
62
+ };
63
+ exports.CommandBus = CommandBus;
64
+ exports.CommandBus = CommandBus = __decorate([
65
+ (0, common_1.Injectable)(),
66
+ __metadata("design:paramtypes", [core_1.ModuleRef,
67
+ pipeline_orchestrator_js_1.PipelineOrchestrator])
68
+ ], CommandBus);
69
+ //# sourceMappingURL=command.bus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.bus.js","sourceRoot":"","sources":["../../../src/lib/services/command.bus.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAkD;AAClD,uCAAyC;AAEzC,iGAAwF;AACxF,yEAAkE;AAElE;;;GAGG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAU;IAGrB,YACmB,SAAoB,EACpB,oBAA0C;QAD1C,cAAS,GAAT,SAAS,CAAW;QACpB,yBAAoB,GAApB,oBAAoB,CAAsB;QAJ5C,aAAQ,GAAG,IAAI,GAAG,EAAsC,CAAC;IAKvE,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,IAAI,CAA4B,OAAiB;QACrD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC;QAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAEnD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,yDAAwB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAC7D,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAA4B,WAAW,EAAE;YACzE,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;QAEH,6BAA6B;QAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,oBAAoB,CAAC,aAAa,CACtD,OAAO,EACP,SAAS,EACT,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAC/B,CAAC;QAEF,MAAM,QAAQ,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,sBAAsB,CACpB,OAAuB,EACvB,OAAmC;QAE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