@rolandsall24/nest-mediator 0.4.3 → 0.5.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/README.md +492 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/behaviors/exception-handling.behavior.d.ts +46 -0
- package/dist/lib/behaviors/exception-handling.behavior.d.ts.map +1 -0
- package/dist/lib/behaviors/exception-handling.behavior.js +76 -0
- package/dist/lib/behaviors/exception-handling.behavior.js.map +1 -0
- package/dist/lib/behaviors/index.d.ts +5 -0
- package/dist/lib/behaviors/index.d.ts.map +1 -0
- package/dist/lib/behaviors/index.js +21 -0
- package/dist/lib/behaviors/index.js.map +1 -0
- package/dist/lib/behaviors/logging.behavior.d.ts +26 -0
- package/dist/lib/behaviors/logging.behavior.d.ts.map +1 -0
- package/dist/lib/behaviors/logging.behavior.js +64 -0
- package/dist/lib/behaviors/logging.behavior.js.map +1 -0
- package/dist/lib/behaviors/performance.behavior.d.ts +41 -0
- package/dist/lib/behaviors/performance.behavior.d.ts.map +1 -0
- package/dist/lib/behaviors/performance.behavior.js +71 -0
- package/dist/lib/behaviors/performance.behavior.js.map +1 -0
- package/dist/lib/behaviors/validation.behavior.d.ts +69 -0
- package/dist/lib/behaviors/validation.behavior.d.ts.map +1 -0
- package/dist/lib/behaviors/validation.behavior.js +137 -0
- package/dist/lib/behaviors/validation.behavior.js.map +1 -0
- package/dist/lib/decorators/index.d.ts +2 -0
- package/dist/lib/decorators/index.d.ts.map +1 -1
- package/dist/lib/decorators/index.js +2 -0
- package/dist/lib/decorators/index.js.map +1 -1
- package/dist/lib/decorators/pipeline-behavior.decorator.d.ts +51 -0
- package/dist/lib/decorators/pipeline-behavior.decorator.d.ts.map +1 -0
- package/dist/lib/decorators/pipeline-behavior.decorator.js +68 -0
- package/dist/lib/decorators/pipeline-behavior.decorator.js.map +1 -0
- package/dist/lib/decorators/skip-behavior.decorator.d.ts +52 -0
- package/dist/lib/decorators/skip-behavior.decorator.d.ts.map +1 -0
- package/dist/lib/decorators/skip-behavior.decorator.js +61 -0
- package/dist/lib/decorators/skip-behavior.decorator.js.map +1 -0
- package/dist/lib/exceptions/handler-not-found.exception.d.ts +20 -0
- package/dist/lib/exceptions/handler-not-found.exception.d.ts.map +1 -0
- package/dist/lib/exceptions/handler-not-found.exception.js +33 -0
- package/dist/lib/exceptions/handler-not-found.exception.js.map +1 -0
- package/dist/lib/exceptions/index.d.ts +3 -0
- package/dist/lib/exceptions/index.d.ts.map +1 -0
- package/dist/lib/exceptions/index.js +19 -0
- package/dist/lib/exceptions/index.js.map +1 -0
- package/dist/lib/exceptions/validation.exception.d.ts +62 -0
- package/dist/lib/exceptions/validation.exception.d.ts.map +1 -0
- package/dist/lib/exceptions/validation.exception.js +66 -0
- package/dist/lib/exceptions/validation.exception.js.map +1 -0
- package/dist/lib/interfaces/index.d.ts +1 -0
- package/dist/lib/interfaces/index.d.ts.map +1 -1
- package/dist/lib/interfaces/index.js +1 -0
- package/dist/lib/interfaces/index.js.map +1 -1
- package/dist/lib/interfaces/pipeline-behavior.interface.d.ts +60 -0
- package/dist/lib/interfaces/pipeline-behavior.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/pipeline-behavior.interface.js +3 -0
- package/dist/lib/interfaces/pipeline-behavior.interface.js.map +1 -0
- package/dist/lib/nest-mediator.module.d.ts +74 -3
- package/dist/lib/nest-mediator.module.d.ts.map +1 -1
- package/dist/lib/nest-mediator.module.js +66 -6
- package/dist/lib/nest-mediator.module.js.map +1 -1
- package/dist/lib/services/mediator.bus.d.ts +54 -4
- package/dist/lib/services/mediator.bus.d.ts.map +1 -1
- package/dist/lib/services/mediator.bus.js +104 -9
- package/dist/lib/services/mediator.bus.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common/interfaces';
|
|
2
|
+
import { IPipelineBehavior } from '../interfaces/pipeline-behavior.interface';
|
|
3
|
+
/**
|
|
4
|
+
* Metadata key for storing behaviors to skip on a command/query class
|
|
5
|
+
*/
|
|
6
|
+
export declare const SKIP_BEHAVIORS_METADATA = "SKIP_BEHAVIORS_METADATA";
|
|
7
|
+
/**
|
|
8
|
+
* Decorator to skip one or more pipeline behaviors for a specific command or query.
|
|
9
|
+
*
|
|
10
|
+
* Works with both built-in behaviors (PerformanceBehavior, LoggingBehavior, etc.)
|
|
11
|
+
* and custom behaviors.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { PerformanceBehavior, LoggingBehavior } from '@rolandsall24/nest-mediator';
|
|
16
|
+
*
|
|
17
|
+
* // Skip a single behavior
|
|
18
|
+
* @SkipBehavior(PerformanceBehavior)
|
|
19
|
+
* export class HighFrequencyCommand {}
|
|
20
|
+
*
|
|
21
|
+
* // Skip multiple behaviors
|
|
22
|
+
* @SkipBehavior([PerformanceBehavior, LoggingBehavior])
|
|
23
|
+
* export class HealthCheckCommand {}
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const SkipBehavior: (behavior: Type<IPipelineBehavior> | Type<IPipelineBehavior>[]) => ClassDecorator;
|
|
27
|
+
/**
|
|
28
|
+
* Decorator to skip multiple pipeline behaviors for a specific command or query.
|
|
29
|
+
*
|
|
30
|
+
* Works with both built-in behaviors and custom behaviors.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import {
|
|
35
|
+
* PerformanceBehavior,
|
|
36
|
+
* LoggingBehavior,
|
|
37
|
+
* ValidationBehavior
|
|
38
|
+
* } from '@rolandsall24/nest-mediator';
|
|
39
|
+
*
|
|
40
|
+
* @SkipBehaviors([PerformanceBehavior, LoggingBehavior])
|
|
41
|
+
* export class HealthCheckCommand {
|
|
42
|
+
* // This command will skip performance and logging behaviors
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* @SkipBehaviors([ValidationBehavior])
|
|
46
|
+
* export class InternalCommand {
|
|
47
|
+
* // This command will skip validation (use with caution!)
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare const SkipBehaviors: (behaviors: Type<IPipelineBehavior>[]) => ClassDecorator;
|
|
52
|
+
//# sourceMappingURL=skip-behavior.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-behavior.decorator.d.ts","sourceRoot":"","sources":["../../../src/lib/decorators/skip-behavior.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAE9E;;GAEG;AACH,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AAEjE;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,YAAY,GACvB,UAAU,IAAI,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,EAAE,KAC5D,cAGF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,aAAa,GACxB,WAAW,IAAI,CAAC,iBAAiB,CAAC,EAAE,KACnC,cAEF,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkipBehaviors = exports.SkipBehavior = exports.SKIP_BEHAVIORS_METADATA = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
/**
|
|
6
|
+
* Metadata key for storing behaviors to skip on a command/query class
|
|
7
|
+
*/
|
|
8
|
+
exports.SKIP_BEHAVIORS_METADATA = 'SKIP_BEHAVIORS_METADATA';
|
|
9
|
+
/**
|
|
10
|
+
* Decorator to skip one or more pipeline behaviors for a specific command or query.
|
|
11
|
+
*
|
|
12
|
+
* Works with both built-in behaviors (PerformanceBehavior, LoggingBehavior, etc.)
|
|
13
|
+
* and custom behaviors.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { PerformanceBehavior, LoggingBehavior } from '@rolandsall24/nest-mediator';
|
|
18
|
+
*
|
|
19
|
+
* // Skip a single behavior
|
|
20
|
+
* @SkipBehavior(PerformanceBehavior)
|
|
21
|
+
* export class HighFrequencyCommand {}
|
|
22
|
+
*
|
|
23
|
+
* // Skip multiple behaviors
|
|
24
|
+
* @SkipBehavior([PerformanceBehavior, LoggingBehavior])
|
|
25
|
+
* export class HealthCheckCommand {}
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
const SkipBehavior = (behavior) => {
|
|
29
|
+
const behaviors = Array.isArray(behavior) ? behavior : [behavior];
|
|
30
|
+
return (0, common_1.SetMetadata)(exports.SKIP_BEHAVIORS_METADATA, behaviors);
|
|
31
|
+
};
|
|
32
|
+
exports.SkipBehavior = SkipBehavior;
|
|
33
|
+
/**
|
|
34
|
+
* Decorator to skip multiple pipeline behaviors for a specific command or query.
|
|
35
|
+
*
|
|
36
|
+
* Works with both built-in behaviors and custom behaviors.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import {
|
|
41
|
+
* PerformanceBehavior,
|
|
42
|
+
* LoggingBehavior,
|
|
43
|
+
* ValidationBehavior
|
|
44
|
+
* } from '@rolandsall24/nest-mediator';
|
|
45
|
+
*
|
|
46
|
+
* @SkipBehaviors([PerformanceBehavior, LoggingBehavior])
|
|
47
|
+
* export class HealthCheckCommand {
|
|
48
|
+
* // This command will skip performance and logging behaviors
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* @SkipBehaviors([ValidationBehavior])
|
|
52
|
+
* export class InternalCommand {
|
|
53
|
+
* // This command will skip validation (use with caution!)
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
const SkipBehaviors = (behaviors) => {
|
|
58
|
+
return (0, common_1.SetMetadata)(exports.SKIP_BEHAVIORS_METADATA, behaviors);
|
|
59
|
+
};
|
|
60
|
+
exports.SkipBehaviors = SkipBehaviors;
|
|
61
|
+
//# sourceMappingURL=skip-behavior.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-behavior.decorator.js","sourceRoot":"","sources":["../../../src/lib/decorators/skip-behavior.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAI7C;;GAEG;AACU,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE;;;;;;;;;;;;;;;;;;GAkBG;AACI,MAAM,YAAY,GAAG,CAC1B,QAA6D,EAC7C,EAAE;IAClB,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAClE,OAAO,IAAA,oBAAW,EAAC,+BAAuB,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC,CAAC;AALW,QAAA,YAAY,gBAKvB;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,aAAa,GAAG,CAC3B,SAAoC,EACpB,EAAE;IAClB,OAAO,IAAA,oBAAW,EAAC,+BAAuB,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC,CAAC;AAJW,QAAA,aAAa,iBAIxB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception thrown when no handler is registered for a request.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* throw new HandlerNotFoundException('CreateUserCommand', 'command');
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare class HandlerNotFoundException extends Error {
|
|
10
|
+
readonly requestName: string;
|
|
11
|
+
readonly requestType: 'command' | 'query';
|
|
12
|
+
constructor(requestName: string, requestType: 'command' | 'query');
|
|
13
|
+
toJSON(): {
|
|
14
|
+
name: string;
|
|
15
|
+
message: string;
|
|
16
|
+
requestName: string;
|
|
17
|
+
requestType: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=handler-not-found.exception.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-not-found.exception.d.ts","sourceRoot":"","sources":["../../../src/lib/exceptions/handler-not-found.exception.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,SAAgB,WAAW,EAAE,MAAM,CAAC;IACpC,SAAgB,WAAW,EAAE,SAAS,GAAG,OAAO,CAAC;gBAErC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,GAAG,OAAO;IAYjE,MAAM,IAAI;QACR,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;KACrB;CAQF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HandlerNotFoundException = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Exception thrown when no handler is registered for a request.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* throw new HandlerNotFoundException('CreateUserCommand', 'command');
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
class HandlerNotFoundException extends Error {
|
|
13
|
+
constructor(requestName, requestType) {
|
|
14
|
+
const message = `No handler registered for ${requestType}: ${requestName}. Did you forget to add @${requestType === 'command' ? 'CommandHandler' : 'QueryHandler'} decorator?`;
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'HandlerNotFoundException';
|
|
17
|
+
this.requestName = requestName;
|
|
18
|
+
this.requestType = requestType;
|
|
19
|
+
if (Error.captureStackTrace) {
|
|
20
|
+
Error.captureStackTrace(this, HandlerNotFoundException);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
toJSON() {
|
|
24
|
+
return {
|
|
25
|
+
name: this.name,
|
|
26
|
+
message: this.message,
|
|
27
|
+
requestName: this.requestName,
|
|
28
|
+
requestType: this.requestType,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.HandlerNotFoundException = HandlerNotFoundException;
|
|
33
|
+
//# sourceMappingURL=handler-not-found.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-not-found.exception.js","sourceRoot":"","sources":["../../../src/lib/exceptions/handler-not-found.exception.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,MAAa,wBAAyB,SAAQ,KAAK;IAIjD,YAAY,WAAmB,EAAE,WAAgC;QAC/D,MAAM,OAAO,GAAG,6BAA6B,WAAW,KAAK,WAAW,4BAA4B,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,cAAc,aAAa,CAAC;QAC/K,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAE/B,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAED,MAAM;QAMJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC;IACJ,CAAC;CACF;AA7BD,4DA6BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./validation.exception.js"), exports);
|
|
18
|
+
__exportStar(require("./handler-not-found.exception.js"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/exceptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,mEAAiD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a single validation error
|
|
3
|
+
*/
|
|
4
|
+
export interface ValidationError {
|
|
5
|
+
/**
|
|
6
|
+
* The property or field that failed validation
|
|
7
|
+
*/
|
|
8
|
+
property: string;
|
|
9
|
+
/**
|
|
10
|
+
* Human-readable error message
|
|
11
|
+
*/
|
|
12
|
+
message: string;
|
|
13
|
+
/**
|
|
14
|
+
* Optional error code for programmatic handling
|
|
15
|
+
*/
|
|
16
|
+
code?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The value that failed validation (optional)
|
|
19
|
+
*/
|
|
20
|
+
value?: any;
|
|
21
|
+
/**
|
|
22
|
+
* Nested validation errors for complex objects
|
|
23
|
+
*/
|
|
24
|
+
children?: ValidationError[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Exception thrown when request validation fails.
|
|
28
|
+
* Contains detailed information about all validation errors.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* throw new ValidationException([
|
|
33
|
+
* { property: 'email', message: 'Email is required' },
|
|
34
|
+
* { property: 'age', message: 'Age must be at least 18', code: 'MIN_AGE' }
|
|
35
|
+
* ]);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class ValidationException extends Error {
|
|
39
|
+
readonly errors: ValidationError[];
|
|
40
|
+
constructor(errors: ValidationError[]);
|
|
41
|
+
/**
|
|
42
|
+
* Format validation errors into a readable message
|
|
43
|
+
*/
|
|
44
|
+
private static formatMessage;
|
|
45
|
+
/**
|
|
46
|
+
* Get errors for a specific property
|
|
47
|
+
*/
|
|
48
|
+
getErrorsForProperty(property: string): ValidationError[];
|
|
49
|
+
/**
|
|
50
|
+
* Check if a specific property has errors
|
|
51
|
+
*/
|
|
52
|
+
hasErrorForProperty(property: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Convert to a plain object for serialization
|
|
55
|
+
*/
|
|
56
|
+
toJSON(): {
|
|
57
|
+
name: string;
|
|
58
|
+
message: string;
|
|
59
|
+
errors: ValidationError[];
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=validation.exception.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.exception.d.ts","sourceRoot":"","sources":["../../../src/lib/exceptions/validation.exception.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,CAAC,EAAE,GAAG,CAAC;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAgB,MAAM,EAAE,eAAe,EAAE,CAAC;gBAE9B,MAAM,EAAE,eAAe,EAAE;IAYrC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAgB5B;;OAEG;IACH,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,EAAE;IAIzD;;OAEG;IACH,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI9C;;OAEG;IACH,MAAM,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,eAAe,EAAE,CAAA;KAAE;CAOvE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationException = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Exception thrown when request validation fails.
|
|
6
|
+
* Contains detailed information about all validation errors.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* throw new ValidationException([
|
|
11
|
+
* { property: 'email', message: 'Email is required' },
|
|
12
|
+
* { property: 'age', message: 'Age must be at least 18', code: 'MIN_AGE' }
|
|
13
|
+
* ]);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
class ValidationException extends Error {
|
|
17
|
+
constructor(errors) {
|
|
18
|
+
const message = ValidationException.formatMessage(errors);
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'ValidationException';
|
|
21
|
+
this.errors = errors;
|
|
22
|
+
// Maintains proper stack trace for where error was thrown (V8 engines)
|
|
23
|
+
if (Error.captureStackTrace) {
|
|
24
|
+
Error.captureStackTrace(this, ValidationException);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Format validation errors into a readable message
|
|
29
|
+
*/
|
|
30
|
+
static formatMessage(errors) {
|
|
31
|
+
if (errors.length === 0) {
|
|
32
|
+
return 'Validation failed';
|
|
33
|
+
}
|
|
34
|
+
if (errors.length === 1) {
|
|
35
|
+
return `Validation failed: ${errors[0].property} - ${errors[0].message}`;
|
|
36
|
+
}
|
|
37
|
+
const errorMessages = errors
|
|
38
|
+
.map((e) => `${e.property}: ${e.message}`)
|
|
39
|
+
.join('; ');
|
|
40
|
+
return `Validation failed with ${errors.length} errors: ${errorMessages}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get errors for a specific property
|
|
44
|
+
*/
|
|
45
|
+
getErrorsForProperty(property) {
|
|
46
|
+
return this.errors.filter((e) => e.property === property);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if a specific property has errors
|
|
50
|
+
*/
|
|
51
|
+
hasErrorForProperty(property) {
|
|
52
|
+
return this.errors.some((e) => e.property === property);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Convert to a plain object for serialization
|
|
56
|
+
*/
|
|
57
|
+
toJSON() {
|
|
58
|
+
return {
|
|
59
|
+
name: this.name,
|
|
60
|
+
message: this.message,
|
|
61
|
+
errors: this.errors,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.ValidationException = ValidationException;
|
|
66
|
+
//# sourceMappingURL=validation.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.exception.js","sourceRoot":"","sources":["../../../src/lib/exceptions/validation.exception.ts"],"names":[],"mappings":";;;AA8BA;;;;;;;;;;;GAWG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAG5C,YAAY,MAAyB;QACnC,MAAM,OAAO,GAAG,mBAAmB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,uEAAuE;QACvE,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,aAAa,CAAC,MAAyB;QACpD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,mBAAmB,CAAC;QAC7B,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,sBAAsB,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3E,CAAC;QAED,MAAM,aAAa,GAAG,MAAM;aACzB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;aACzC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,OAAO,0BAA0B,MAAM,CAAC,MAAM,YAAY,aAAa,EAAE,CAAC;IAC5E,CAAC;IAED;;OAEG;IACH,oBAAoB,CAAC,QAAgB;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,mBAAmB,CAAC,QAAgB;QAClC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;CACF;AA1DD,kDA0DC"}
|
|
@@ -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"}
|
|
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"}
|
|
@@ -18,4 +18,5 @@ __exportStar(require("./command.interface.js"), exports);
|
|
|
18
18
|
__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
|
+
__exportStar(require("./pipeline-behavior.interface.js"), exports);
|
|
21
22
|
//# 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"}
|
|
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"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline behavior interface for implementing cross-cutting concerns.
|
|
3
|
+
* Behaviors wrap around request handlers, allowing pre/post processing.
|
|
4
|
+
*
|
|
5
|
+
* @template TRequest - The request type (command or query)
|
|
6
|
+
* @template TResponse - The response type
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Injectable()
|
|
11
|
+
* @PipelineBehavior({ priority: 100 })
|
|
12
|
+
* export class LoggingBehavior<TRequest, TResponse>
|
|
13
|
+
* implements IPipelineBehavior<TRequest, TResponse> {
|
|
14
|
+
*
|
|
15
|
+
* async handle(request: TRequest, next: () => Promise<TResponse>): Promise<TResponse> {
|
|
16
|
+
* console.log('Before handler');
|
|
17
|
+
* const response = await next();
|
|
18
|
+
* console.log('After handler');
|
|
19
|
+
* return response;
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export interface IPipelineBehavior<TRequest = any, TResponse = any> {
|
|
25
|
+
/**
|
|
26
|
+
* Handle the request by executing pre-processing logic,
|
|
27
|
+
* calling the next behavior/handler in the pipeline,
|
|
28
|
+
* and executing post-processing logic.
|
|
29
|
+
*
|
|
30
|
+
* @param request - The incoming request object
|
|
31
|
+
* @param next - Delegate to invoke the next behavior or final handler
|
|
32
|
+
* @returns Promise with the response
|
|
33
|
+
*/
|
|
34
|
+
handle(request: TRequest, next: () => Promise<TResponse>): Promise<TResponse>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Options for configuring pipeline behavior
|
|
38
|
+
*/
|
|
39
|
+
export interface PipelineBehaviorOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Execution priority (lower numbers execute first).
|
|
42
|
+
* Default: 0
|
|
43
|
+
*
|
|
44
|
+
* Suggested priority ranges:
|
|
45
|
+
* - -100 to -1: Exception handling (outermost)
|
|
46
|
+
* - 0 to 99: Logging, performance tracking
|
|
47
|
+
* - 100 to 199: Validation
|
|
48
|
+
* - 200+: Transaction/Unit of Work (innermost)
|
|
49
|
+
*/
|
|
50
|
+
priority?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Scope of the behavior.
|
|
53
|
+
* - 'command': Only applies to commands (send)
|
|
54
|
+
* - 'query': Only applies to queries (query)
|
|
55
|
+
* - 'all': Applies to both commands and queries
|
|
56
|
+
* Default: 'all'
|
|
57
|
+
*/
|
|
58
|
+
scope?: 'command' | 'query' | 'all';
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=pipeline-behavior.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-behavior.interface.d.ts","sourceRoot":"","sources":["../../../src/lib/interfaces/pipeline-behavior.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,iBAAiB,CAAC,QAAQ,GAAG,GAAG,EAAE,SAAS,GAAG,GAAG;IAChE;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CAC/E;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,CAAC;CACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-behavior.interface.js","sourceRoot":"","sources":["../../../src/lib/interfaces/pipeline-behavior.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,53 @@
|
|
|
1
|
-
import { DynamicModule, OnModuleInit } from '@nestjs/common';
|
|
1
|
+
import { DynamicModule, Type, 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
|
+
/**
|
|
6
|
+
* Configuration options for NestMediatorModule
|
|
7
|
+
*/
|
|
8
|
+
export interface NestMediatorModuleOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Enable built-in logging behavior.
|
|
11
|
+
* Logs request handling with timing information.
|
|
12
|
+
* Default: false
|
|
13
|
+
*/
|
|
14
|
+
enableLogging?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Enable built-in validation behavior.
|
|
17
|
+
* Validates requests using class-validator if available.
|
|
18
|
+
* Default: false
|
|
19
|
+
*/
|
|
20
|
+
enableValidation?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Enable built-in exception handling behavior.
|
|
23
|
+
* Provides centralized exception logging.
|
|
24
|
+
* Default: false
|
|
25
|
+
*/
|
|
26
|
+
enableExceptionHandling?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Enable built-in performance tracking behavior.
|
|
29
|
+
* Logs warnings for slow requests.
|
|
30
|
+
* Default: false
|
|
31
|
+
*/
|
|
32
|
+
enablePerformanceTracking?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Performance threshold in milliseconds.
|
|
35
|
+
* Requests exceeding this will be logged as warnings.
|
|
36
|
+
* Only applies when enablePerformanceTracking is true.
|
|
37
|
+
* Default: 500
|
|
38
|
+
*/
|
|
39
|
+
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
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Token for module options injection
|
|
49
|
+
*/
|
|
50
|
+
export declare const NEST_MEDIATOR_OPTIONS = "NEST_MEDIATOR_OPTIONS";
|
|
4
51
|
export declare class NestMediatorModule implements OnModuleInit {
|
|
5
52
|
private readonly mediatorBus;
|
|
6
53
|
private readonly reflector;
|
|
@@ -8,10 +55,34 @@ export declare class NestMediatorModule implements OnModuleInit {
|
|
|
8
55
|
constructor(mediatorBus: MediatorBus, reflector: Reflector, discoveryService: DiscoveryService);
|
|
9
56
|
onModuleInit(): void;
|
|
10
57
|
/**
|
|
11
|
-
* Register the NestMediator module
|
|
12
|
-
* Handlers are automatically discovered from the application's providers
|
|
58
|
+
* Register the NestMediator module with default settings.
|
|
59
|
+
* Handlers and behaviors are automatically discovered from the application's providers.
|
|
13
60
|
* @returns Dynamic module
|
|
14
61
|
*/
|
|
15
62
|
static forRoot(): DynamicModule;
|
|
63
|
+
/**
|
|
64
|
+
* Register the NestMediator module with custom configuration.
|
|
65
|
+
*
|
|
66
|
+
* @param options - Configuration options
|
|
67
|
+
* @returns Dynamic module
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* // Enable built-in behaviors
|
|
72
|
+
* NestMediatorModule.forRootAsync({
|
|
73
|
+
* enableLogging: true,
|
|
74
|
+
* enableValidation: true,
|
|
75
|
+
* enableExceptionHandling: true,
|
|
76
|
+
* enablePerformanceTracking: true,
|
|
77
|
+
* performanceThresholdMs: 1000,
|
|
78
|
+
* })
|
|
79
|
+
*
|
|
80
|
+
* // With custom behaviors
|
|
81
|
+
* NestMediatorModule.forRootAsync({
|
|
82
|
+
* behaviors: [MyCustomBehavior],
|
|
83
|
+
* })
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
static forRootAsync(options?: NestMediatorModuleOptions): DynamicModule;
|
|
16
87
|
}
|
|
17
88
|
//# 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,EAAU,IAAI,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAmB,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAMlD,OAAO,EAKL,iBAAiB,EAElB,MAAM,uBAAuB,CAAC;AAQ/B;;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;IAEhC;;;;OAIG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;CACjD;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;;;;OAIG;IACH,MAAM,CAAC,OAAO,IAAI,aAAa;IAI/B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,GAAE,yBAA8B,GAAG,aAAa;CAwC5E"}
|