@rolandsall24/nest-mediator 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Version 0.5.0 introduces **Pipeline Behaviors** while maintaining backward compa
|
|
|
40
40
|
|
|
41
41
|
- Pipeline behaviors for cross-cutting concerns (logging, validation, etc.)
|
|
42
42
|
- Built-in behaviors: `LoggingBehavior`, `ValidationBehavior`, `ExceptionHandlingBehavior`, `PerformanceBehavior`
|
|
43
|
-
- New `
|
|
43
|
+
- New `forRoot()` method for enabling behaviors
|
|
44
44
|
- Custom `HandlerNotFoundException` for better error handling
|
|
45
45
|
|
|
46
46
|
### Breaking Change Notice
|
|
@@ -71,14 +71,14 @@ try {
|
|
|
71
71
|
|
|
72
72
|
### No Migration Required
|
|
73
73
|
|
|
74
|
-
If you're using `NestMediatorModule.forRoot()`, no changes are needed. Pipeline behaviors are **opt-in** via `
|
|
74
|
+
If you're using `NestMediatorModule.forRoot()`, no changes are needed. Pipeline behaviors are **opt-in** via `forRoot()`:
|
|
75
75
|
|
|
76
76
|
```typescript
|
|
77
77
|
// Existing code - works exactly as before (no behaviors)
|
|
78
78
|
NestMediatorModule.forRoot()
|
|
79
79
|
|
|
80
80
|
// New - opt-in to behaviors
|
|
81
|
-
NestMediatorModule.
|
|
81
|
+
NestMediatorModule.forRoot({
|
|
82
82
|
enableLogging: true,
|
|
83
83
|
enableValidation: true,
|
|
84
84
|
})
|
|
@@ -116,7 +116,7 @@ Or with built-in pipeline behaviors enabled:
|
|
|
116
116
|
```typescript
|
|
117
117
|
@Module({
|
|
118
118
|
imports: [
|
|
119
|
-
NestMediatorModule.
|
|
119
|
+
NestMediatorModule.forRoot({
|
|
120
120
|
enableLogging: true, // Log request handling with timing
|
|
121
121
|
enableValidation: true, // Validate requests with class-validator
|
|
122
122
|
enableExceptionHandling: true, // Centralized exception logging
|
|
@@ -585,7 +585,7 @@ import { UserPersistenceAdapter } from './infrastructure/persistence/user/user-p
|
|
|
585
585
|
@Module({
|
|
586
586
|
imports: [
|
|
587
587
|
// Enable pipeline behaviors for logging, validation, and error handling
|
|
588
|
-
NestMediatorModule.
|
|
588
|
+
NestMediatorModule.forRoot({
|
|
589
589
|
enableLogging: true,
|
|
590
590
|
enableValidation: true,
|
|
591
591
|
enableExceptionHandling: true,
|
|
@@ -747,7 +747,7 @@ Executes a query through its registered handler.
|
|
|
747
747
|
|
|
748
748
|
Basic module registration with no built-in behaviors.
|
|
749
749
|
|
|
750
|
-
#### `NestMediatorModule.
|
|
750
|
+
#### `NestMediatorModule.forRoot(options)`
|
|
751
751
|
|
|
752
752
|
Module registration with configuration options.
|
|
753
753
|
|
|
@@ -758,7 +758,6 @@ Module registration with configuration options.
|
|
|
758
758
|
| `enableExceptionHandling` | boolean | false | Enable centralized exception logging |
|
|
759
759
|
| `enablePerformanceTracking` | boolean | false | Enable slow request warnings |
|
|
760
760
|
| `performanceThresholdMs` | number | 500 | Threshold for slow request warnings |
|
|
761
|
-
| `behaviors` | Type[] | [] | Additional custom behaviors to register |
|
|
762
761
|
|
|
763
762
|
## Pipeline Behaviors
|
|
764
763
|
|
|
@@ -772,7 +771,7 @@ import { NestMediatorModule } from '@rolandsall24/nest-mediator';
|
|
|
772
771
|
|
|
773
772
|
@Module({
|
|
774
773
|
imports: [
|
|
775
|
-
NestMediatorModule.
|
|
774
|
+
NestMediatorModule.forRoot({
|
|
776
775
|
enableLogging: true, // Logs request handling with timing
|
|
777
776
|
enableValidation: true, // Validates requests using class-validator
|
|
778
777
|
enableExceptionHandling: true, // Centralized exception logging
|
|
@@ -839,28 +838,12 @@ export class MyCustomBehavior<TRequest, TResponse>
|
|
|
839
838
|
|
|
840
839
|
### Registering Custom Behaviors
|
|
841
840
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
```typescript
|
|
845
|
-
@Module({
|
|
846
|
-
imports: [
|
|
847
|
-
NestMediatorModule.forRootAsync({
|
|
848
|
-
behaviors: [MyCustomBehavior],
|
|
849
|
-
}),
|
|
850
|
-
],
|
|
851
|
-
providers: [
|
|
852
|
-
MyCustomBehavior, // Also add to providers for DI
|
|
853
|
-
],
|
|
854
|
-
})
|
|
855
|
-
export class AppModule {}
|
|
856
|
-
```
|
|
857
|
-
|
|
858
|
-
Or use the `@PipelineBehavior` decorator and add to providers - it will be auto-discovered:
|
|
841
|
+
Custom behaviors with the `@PipelineBehavior` decorator are auto-discovered. Just add them to your module's providers:
|
|
859
842
|
|
|
860
843
|
```typescript
|
|
861
844
|
@Module({
|
|
862
845
|
imports: [NestMediatorModule.forRoot()],
|
|
863
|
-
providers: [MyCustomBehavior], // Auto-discovered via decorator
|
|
846
|
+
providers: [MyCustomBehavior], // Auto-discovered via @PipelineBehavior decorator
|
|
864
847
|
})
|
|
865
848
|
export class AppModule {}
|
|
866
849
|
```
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { DynamicModule,
|
|
1
|
+
import { DynamicModule, OnModuleInit } from '@nestjs/common';
|
|
2
2
|
import { Reflector, DiscoveryService } from '@nestjs/core';
|
|
3
3
|
import { MediatorBus } from './services/index.js';
|
|
4
|
-
import { IPipelineBehavior } from './interfaces/index.js';
|
|
5
4
|
/**
|
|
6
5
|
* Configuration options for NestMediatorModule
|
|
7
6
|
*/
|
|
@@ -37,12 +36,6 @@ export interface NestMediatorModuleOptions {
|
|
|
37
36
|
* Default: 500
|
|
38
37
|
*/
|
|
39
38
|
performanceThresholdMs?: number;
|
|
40
|
-
/**
|
|
41
|
-
* Custom pipeline behaviors to register.
|
|
42
|
-
* These will be registered in addition to any behaviors
|
|
43
|
-
* discovered via @PipelineBehavior decorator.
|
|
44
|
-
*/
|
|
45
|
-
behaviors?: Type<IPipelineBehavior<any, any>>[];
|
|
46
39
|
}
|
|
47
40
|
/**
|
|
48
41
|
* Token for module options injection
|
|
@@ -55,34 +48,27 @@ export declare class NestMediatorModule implements OnModuleInit {
|
|
|
55
48
|
constructor(mediatorBus: MediatorBus, reflector: Reflector, discoveryService: DiscoveryService);
|
|
56
49
|
onModuleInit(): void;
|
|
57
50
|
/**
|
|
58
|
-
* Register the NestMediator module
|
|
51
|
+
* Register the NestMediator module.
|
|
59
52
|
* Handlers and behaviors are automatically discovered from the application's providers.
|
|
60
|
-
* @returns Dynamic module
|
|
61
|
-
*/
|
|
62
|
-
static forRoot(): DynamicModule;
|
|
63
|
-
/**
|
|
64
|
-
* Register the NestMediator module with custom configuration.
|
|
65
53
|
*
|
|
66
|
-
* @param options -
|
|
54
|
+
* @param options - Optional configuration options
|
|
67
55
|
* @returns Dynamic module
|
|
68
56
|
*
|
|
69
57
|
* @example
|
|
70
58
|
* ```typescript
|
|
59
|
+
* // Basic setup (no built-in behaviors)
|
|
60
|
+
* NestMediatorModule.forRoot()
|
|
61
|
+
*
|
|
71
62
|
* // Enable built-in behaviors
|
|
72
|
-
* NestMediatorModule.
|
|
63
|
+
* NestMediatorModule.forRoot({
|
|
73
64
|
* enableLogging: true,
|
|
74
65
|
* enableValidation: true,
|
|
75
66
|
* enableExceptionHandling: true,
|
|
76
67
|
* enablePerformanceTracking: true,
|
|
77
68
|
* performanceThresholdMs: 1000,
|
|
78
69
|
* })
|
|
79
|
-
*
|
|
80
|
-
* // With custom behaviors
|
|
81
|
-
* NestMediatorModule.forRootAsync({
|
|
82
|
-
* behaviors: [MyCustomBehavior],
|
|
83
|
-
* })
|
|
84
70
|
* ```
|
|
85
71
|
*/
|
|
86
|
-
static
|
|
72
|
+
static forRoot(options?: NestMediatorModuleOptions): DynamicModule;
|
|
87
73
|
}
|
|
88
74
|
//# sourceMappingURL=nest-mediator.module.d.ts.map
|
|
@@ -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,
|
|
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;IAoEZ;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,yBAA8B,GAAG,aAAa;CAoCvE"}
|
|
@@ -59,37 +59,28 @@ let NestMediatorModule = NestMediatorModule_1 = class NestMediatorModule {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Register the NestMediator module
|
|
62
|
+
* Register the NestMediator module.
|
|
63
63
|
* Handlers and behaviors are automatically discovered from the application's providers.
|
|
64
|
-
* @returns Dynamic module
|
|
65
|
-
*/
|
|
66
|
-
static forRoot() {
|
|
67
|
-
return this.forRootAsync({});
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Register the NestMediator module with custom configuration.
|
|
71
64
|
*
|
|
72
|
-
* @param options -
|
|
65
|
+
* @param options - Optional configuration options
|
|
73
66
|
* @returns Dynamic module
|
|
74
67
|
*
|
|
75
68
|
* @example
|
|
76
69
|
* ```typescript
|
|
70
|
+
* // Basic setup (no built-in behaviors)
|
|
71
|
+
* NestMediatorModule.forRoot()
|
|
72
|
+
*
|
|
77
73
|
* // Enable built-in behaviors
|
|
78
|
-
* NestMediatorModule.
|
|
74
|
+
* NestMediatorModule.forRoot({
|
|
79
75
|
* enableLogging: true,
|
|
80
76
|
* enableValidation: true,
|
|
81
77
|
* enableExceptionHandling: true,
|
|
82
78
|
* enablePerformanceTracking: true,
|
|
83
79
|
* performanceThresholdMs: 1000,
|
|
84
80
|
* })
|
|
85
|
-
*
|
|
86
|
-
* // With custom behaviors
|
|
87
|
-
* NestMediatorModule.forRootAsync({
|
|
88
|
-
* behaviors: [MyCustomBehavior],
|
|
89
|
-
* })
|
|
90
81
|
* ```
|
|
91
82
|
*/
|
|
92
|
-
static
|
|
83
|
+
static forRoot(options = {}) {
|
|
93
84
|
const builtInProviders = [];
|
|
94
85
|
// Add built-in behaviors based on options
|
|
95
86
|
if (options.enableExceptionHandling) {
|
|
@@ -104,8 +95,6 @@ let NestMediatorModule = NestMediatorModule_1 = class NestMediatorModule {
|
|
|
104
95
|
if (options.enableValidation) {
|
|
105
96
|
builtInProviders.push(index_js_3.ValidationBehavior);
|
|
106
97
|
}
|
|
107
|
-
// Add custom behaviors
|
|
108
|
-
const customBehaviors = options.behaviors ?? [];
|
|
109
98
|
return {
|
|
110
99
|
module: NestMediatorModule_1,
|
|
111
100
|
imports: [core_1.DiscoveryModule],
|
|
@@ -113,7 +102,6 @@ let NestMediatorModule = NestMediatorModule_1 = class NestMediatorModule {
|
|
|
113
102
|
index_js_1.MediatorBus,
|
|
114
103
|
core_1.Reflector,
|
|
115
104
|
...builtInProviders,
|
|
116
|
-
...customBehaviors,
|
|
117
105
|
{
|
|
118
106
|
provide: exports.NEST_MEDIATOR_OPTIONS,
|
|
119
107
|
useValue: options,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nest-mediator.module.js","sourceRoot":"","sources":["../../src/lib/nest-mediator.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,uCAA4E;AAC5E,kDAAkD;AAClD,oDAI+B;AAS/B,mDAK8B;
|
|
1
|
+
{"version":3,"file":"nest-mediator.module.js","sourceRoot":"","sources":["../../src/lib/nest-mediator.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,uCAA4E;AAC5E,kDAAkD;AAClD,oDAI+B;AAS/B,mDAK8B;AA2C9B;;GAEG;AACU,QAAA,qBAAqB,GAAG,uBAAuB,CAAC;AAGtD,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAC7B,YACmB,WAAwB,EACxB,SAAoB,EACpB,gBAAkC;QAFlC,gBAAW,GAAX,WAAW,CAAa;QACxB,cAAS,GAAT,SAAS,CAAW;QACpB,qBAAgB,GAAhB,gBAAgB,CAAkB;IAClD,CAAC;IAEJ,YAAY;QACV,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC;QAEvD,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;gBAC3C,SAAS;YACX,CAAC;YAED,MAAM,UAAU,GAAG,OAAO,OAAO,CAAC,QAAQ,KAAK,UAAU,CAAC;YAC1D,MAAM,aAAa,GACjB,UAAU,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,KAAK,SAAS,CAAC;YAEzD,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,SAAS;YACX,CAAC;YAED,MAAM,WAAW,GAAG,OAAO,CAAC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,uBAAuB,EAAE,CAAC;YACpC,gBAAgB,CAAC,IAAI,CAAC,oCAAyB,CAAC,CAAC;QACnD,CAAC;QAED,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;YAC1B,gBAAgB,CAAC,IAAI,CAAC,0BAAe,CAAC,CAAC;QACzC,CAAC;QAED,IAAI,OAAO,CAAC,yBAAyB,EAAE,CAAC;YACtC,gBAAgB,CAAC,IAAI,CAAC,8BAAmB,CAAC,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,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;AArIY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,eAAM,EAAC,EAAE,CAAC;qCAGuB,sBAAW;QACb,gBAAS;QACF,uBAAgB;GAJ1C,kBAAkB,CAqI9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rolandsall24/nest-mediator",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "A lightweight CQRS (Command Query Responsibility Segregation) mediator pattern implementation for NestJS applications",
|
|
5
5
|
"author": "Roland Salloum",
|
|
6
6
|
"license": "MIT",
|