@pawells/nestjs-shared 1.0.0-dev.4c8c698
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/LICENSE +21 -0
- package/README.md +802 -0
- package/build/LICENSE +21 -0
- package/build/README.md +802 -0
- package/build/common/common.module.d.ts +49 -0
- package/build/common/common.module.d.ts.map +1 -0
- package/build/common/common.module.js +178 -0
- package/build/common/common.module.js.map +1 -0
- package/build/common/constants/histogram-buckets.constants.d.ts +12 -0
- package/build/common/constants/histogram-buckets.constants.d.ts.map +1 -0
- package/build/common/constants/histogram-buckets.constants.js +51 -0
- package/build/common/constants/histogram-buckets.constants.js.map +1 -0
- package/build/common/constants/http-status.constants.d.ts +27 -0
- package/build/common/constants/http-status.constants.d.ts.map +1 -0
- package/build/common/constants/http-status.constants.js +27 -0
- package/build/common/constants/http-status.constants.js.map +1 -0
- package/build/common/constants/timeout.constants.d.ts +29 -0
- package/build/common/constants/timeout.constants.d.ts.map +1 -0
- package/build/common/constants/timeout.constants.js +45 -0
- package/build/common/constants/timeout.constants.js.map +1 -0
- package/build/common/controllers/metrics.controller.d.ts +23 -0
- package/build/common/controllers/metrics.controller.d.ts.map +1 -0
- package/build/common/controllers/metrics.controller.js +66 -0
- package/build/common/controllers/metrics.controller.js.map +1 -0
- package/build/common/decorators/common-decorators.d.ts +90 -0
- package/build/common/decorators/common-decorators.d.ts.map +1 -0
- package/build/common/decorators/common-decorators.js +101 -0
- package/build/common/decorators/common-decorators.js.map +1 -0
- package/build/common/decorators/decorator-factory.d.ts +108 -0
- package/build/common/decorators/decorator-factory.d.ts.map +1 -0
- package/build/common/decorators/decorator-factory.js +104 -0
- package/build/common/decorators/decorator-factory.js.map +1 -0
- package/build/common/decorators/guard.decorators.d.ts +48 -0
- package/build/common/decorators/guard.decorators.d.ts.map +1 -0
- package/build/common/decorators/guard.decorators.js +49 -0
- package/build/common/decorators/guard.decorators.js.map +1 -0
- package/build/common/decorators/index.d.ts +10 -0
- package/build/common/decorators/index.d.ts.map +1 -0
- package/build/common/decorators/index.js +11 -0
- package/build/common/decorators/index.js.map +1 -0
- package/build/common/decorators/instrument.decorator.d.ts +128 -0
- package/build/common/decorators/instrument.decorator.d.ts.map +1 -0
- package/build/common/decorators/instrument.decorator.js +165 -0
- package/build/common/decorators/instrument.decorator.js.map +1 -0
- package/build/common/decorators/metric.decorators.d.ts +42 -0
- package/build/common/decorators/metric.decorators.d.ts.map +1 -0
- package/build/common/decorators/metric.decorators.js +85 -0
- package/build/common/decorators/metric.decorators.js.map +1 -0
- package/build/common/decorators/request-property.decorator.d.ts +65 -0
- package/build/common/decorators/request-property.decorator.d.ts.map +1 -0
- package/build/common/decorators/request-property.decorator.js +102 -0
- package/build/common/decorators/request-property.decorator.js.map +1 -0
- package/build/common/errors/base-application-error.d.ts +98 -0
- package/build/common/errors/base-application-error.d.ts.map +1 -0
- package/build/common/errors/base-application-error.js +133 -0
- package/build/common/errors/base-application-error.js.map +1 -0
- package/build/common/errors/error-factory.d.ts +93 -0
- package/build/common/errors/error-factory.d.ts.map +1 -0
- package/build/common/errors/error-factory.js +105 -0
- package/build/common/errors/error-factory.js.map +1 -0
- package/build/common/errors/index.d.ts +13 -0
- package/build/common/errors/index.d.ts.map +1 -0
- package/build/common/errors/index.js +15 -0
- package/build/common/errors/index.js.map +1 -0
- package/build/common/factories/index.d.ts +5 -0
- package/build/common/factories/index.d.ts.map +1 -0
- package/build/common/factories/index.js +3 -0
- package/build/common/factories/index.js.map +1 -0
- package/build/common/factories/module-factory.d.ts +178 -0
- package/build/common/factories/module-factory.d.ts.map +1 -0
- package/build/common/factories/module-factory.js +253 -0
- package/build/common/factories/module-factory.js.map +1 -0
- package/build/common/factories/rate-limit-config.factory.d.ts +79 -0
- package/build/common/factories/rate-limit-config.factory.d.ts.map +1 -0
- package/build/common/factories/rate-limit-config.factory.js +115 -0
- package/build/common/factories/rate-limit-config.factory.js.map +1 -0
- package/build/common/factories/security-bootstrap.factory.d.ts +77 -0
- package/build/common/factories/security-bootstrap.factory.d.ts.map +1 -0
- package/build/common/factories/security-bootstrap.factory.js +222 -0
- package/build/common/factories/security-bootstrap.factory.js.map +1 -0
- package/build/common/filters/global-exception.filter.d.ts +78 -0
- package/build/common/filters/global-exception.filter.d.ts.map +1 -0
- package/build/common/filters/global-exception.filter.js +192 -0
- package/build/common/filters/global-exception.filter.js.map +1 -0
- package/build/common/filters/http-exception.filter.d.ts +37 -0
- package/build/common/filters/http-exception.filter.d.ts.map +1 -0
- package/build/common/filters/http-exception.filter.js +91 -0
- package/build/common/filters/http-exception.filter.js.map +1 -0
- package/build/common/guards/csrf.guard.d.ts +53 -0
- package/build/common/guards/csrf.guard.d.ts.map +1 -0
- package/build/common/guards/csrf.guard.js +109 -0
- package/build/common/guards/csrf.guard.js.map +1 -0
- package/build/common/guards/metrics.guard.d.ts +42 -0
- package/build/common/guards/metrics.guard.d.ts.map +1 -0
- package/build/common/guards/metrics.guard.js +124 -0
- package/build/common/guards/metrics.guard.js.map +1 -0
- package/build/common/index.d.ts +43 -0
- package/build/common/index.d.ts.map +1 -0
- package/build/common/index.js +50 -0
- package/build/common/index.js.map +1 -0
- package/build/common/interceptors/http-client.interceptor.d.ts +11 -0
- package/build/common/interceptors/http-client.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/http-client.interceptor.js +69 -0
- package/build/common/interceptors/http-client.interceptor.js.map +1 -0
- package/build/common/interceptors/http-instrumentation.interceptor.d.ts +64 -0
- package/build/common/interceptors/http-instrumentation.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/http-instrumentation.interceptor.js +148 -0
- package/build/common/interceptors/http-instrumentation.interceptor.js.map +1 -0
- package/build/common/interceptors/http-metrics.interceptor.d.ts +46 -0
- package/build/common/interceptors/http-metrics.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/http-metrics.interceptor.js +120 -0
- package/build/common/interceptors/http-metrics.interceptor.js.map +1 -0
- package/build/common/interceptors/logging.interceptor.d.ts +22 -0
- package/build/common/interceptors/logging.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/logging.interceptor.js +67 -0
- package/build/common/interceptors/logging.interceptor.js.map +1 -0
- package/build/common/interfaces/cache-provider.interface.d.ts +54 -0
- package/build/common/interfaces/cache-provider.interface.d.ts.map +1 -0
- package/build/common/interfaces/cache-provider.interface.js +6 -0
- package/build/common/interfaces/cache-provider.interface.js.map +1 -0
- package/build/common/interfaces/index.d.ts +7 -0
- package/build/common/interfaces/index.d.ts.map +1 -0
- package/build/common/interfaces/index.js +3 -0
- package/build/common/interfaces/index.js.map +1 -0
- package/build/common/interfaces/log-context.interface.d.ts +77 -0
- package/build/common/interfaces/log-context.interface.d.ts.map +1 -0
- package/build/common/interfaces/log-context.interface.js +2 -0
- package/build/common/interfaces/log-context.interface.js.map +1 -0
- package/build/common/interfaces/log-entry.interface.d.ts +26 -0
- package/build/common/interfaces/log-entry.interface.d.ts.map +1 -0
- package/build/common/interfaces/log-entry.interface.js +33 -0
- package/build/common/interfaces/log-entry.interface.js.map +1 -0
- package/build/common/interfaces/logger.interface.d.ts +62 -0
- package/build/common/interfaces/logger.interface.d.ts.map +1 -0
- package/build/common/interfaces/logger.interface.js +2 -0
- package/build/common/interfaces/logger.interface.js.map +1 -0
- package/build/common/interfaces/metrics-exporter.interface.d.ts +275 -0
- package/build/common/interfaces/metrics-exporter.interface.d.ts.map +1 -0
- package/build/common/interfaces/metrics-exporter.interface.js +8 -0
- package/build/common/interfaces/metrics-exporter.interface.js.map +1 -0
- package/build/common/metrics/base-metrics-collector.d.ts +81 -0
- package/build/common/metrics/base-metrics-collector.d.ts.map +1 -0
- package/build/common/metrics/base-metrics-collector.js +88 -0
- package/build/common/metrics/base-metrics-collector.js.map +1 -0
- package/build/common/metrics/index.d.ts +2 -0
- package/build/common/metrics/index.d.ts.map +1 -0
- package/build/common/metrics/index.js +2 -0
- package/build/common/metrics/index.js.map +1 -0
- package/build/common/metrics.module.d.ts +50 -0
- package/build/common/metrics.module.d.ts.map +1 -0
- package/build/common/metrics.module.js +77 -0
- package/build/common/metrics.module.js.map +1 -0
- package/build/common/modules/throttler.module.d.ts +69 -0
- package/build/common/modules/throttler.module.d.ts.map +1 -0
- package/build/common/modules/throttler.module.js +117 -0
- package/build/common/modules/throttler.module.js.map +1 -0
- package/build/common/pipes/base-validation.pipe.d.ts +67 -0
- package/build/common/pipes/base-validation.pipe.d.ts.map +1 -0
- package/build/common/pipes/base-validation.pipe.js +95 -0
- package/build/common/pipes/base-validation.pipe.js.map +1 -0
- package/build/common/pipes/validation.pipe.d.ts +32 -0
- package/build/common/pipes/validation.pipe.d.ts.map +1 -0
- package/build/common/pipes/validation.pipe.js +60 -0
- package/build/common/pipes/validation.pipe.js.map +1 -0
- package/build/common/registry/instrumentation-registry.d.ts +227 -0
- package/build/common/registry/instrumentation-registry.d.ts.map +1 -0
- package/build/common/registry/instrumentation-registry.js +414 -0
- package/build/common/registry/instrumentation-registry.js.map +1 -0
- package/build/common/services/audit-logger.service.d.ts +91 -0
- package/build/common/services/audit-logger.service.d.ts.map +1 -0
- package/build/common/services/audit-logger.service.js +180 -0
- package/build/common/services/audit-logger.service.js.map +1 -0
- package/build/common/services/csrf.service.d.ts +202 -0
- package/build/common/services/csrf.service.d.ts.map +1 -0
- package/build/common/services/csrf.service.js +478 -0
- package/build/common/services/csrf.service.js.map +1 -0
- package/build/common/services/error-categorizer.service.d.ts +82 -0
- package/build/common/services/error-categorizer.service.d.ts.map +1 -0
- package/build/common/services/error-categorizer.service.js +339 -0
- package/build/common/services/error-categorizer.service.js.map +1 -0
- package/build/common/services/error-sanitizer.service.d.ts +146 -0
- package/build/common/services/error-sanitizer.service.d.ts.map +1 -0
- package/build/common/services/error-sanitizer.service.js +287 -0
- package/build/common/services/error-sanitizer.service.js.map +1 -0
- package/build/common/services/health-check.service.d.ts +86 -0
- package/build/common/services/health-check.service.d.ts.map +1 -0
- package/build/common/services/health-check.service.js +132 -0
- package/build/common/services/health-check.service.js.map +1 -0
- package/build/common/services/http-client.service.d.ts +113 -0
- package/build/common/services/http-client.service.d.ts.map +1 -0
- package/build/common/services/http-client.service.js +294 -0
- package/build/common/services/http-client.service.js.map +1 -0
- package/build/common/services/logger.service.d.ts +189 -0
- package/build/common/services/logger.service.d.ts.map +1 -0
- package/build/common/services/logger.service.js +423 -0
- package/build/common/services/logger.service.js.map +1 -0
- package/build/common/services/metrics-registry.service.d.ts +98 -0
- package/build/common/services/metrics-registry.service.d.ts.map +1 -0
- package/build/common/services/metrics-registry.service.js +262 -0
- package/build/common/services/metrics-registry.service.js.map +1 -0
- package/build/common/services/nest-logger-adapter.service.d.ts +62 -0
- package/build/common/services/nest-logger-adapter.service.d.ts.map +1 -0
- package/build/common/services/nest-logger-adapter.service.js +120 -0
- package/build/common/services/nest-logger-adapter.service.js.map +1 -0
- package/build/common/utils/error.utils.d.ts +16 -0
- package/build/common/utils/error.utils.d.ts.map +1 -0
- package/build/common/utils/error.utils.js +26 -0
- package/build/common/utils/error.utils.js.map +1 -0
- package/build/common/utils/lazy-getter.types.d.ts +190 -0
- package/build/common/utils/lazy-getter.types.d.ts.map +1 -0
- package/build/common/utils/lazy-getter.types.js +114 -0
- package/build/common/utils/lazy-getter.types.js.map +1 -0
- package/build/common/utils/module.utils.d.ts +33 -0
- package/build/common/utils/module.utils.d.ts.map +1 -0
- package/build/common/utils/module.utils.js +48 -0
- package/build/common/utils/module.utils.js.map +1 -0
- package/build/common/utils/sanitization.utils.d.ts +69 -0
- package/build/common/utils/sanitization.utils.d.ts.map +1 -0
- package/build/common/utils/sanitization.utils.js +141 -0
- package/build/common/utils/sanitization.utils.js.map +1 -0
- package/build/config/config.module.d.ts +30 -0
- package/build/config/config.module.d.ts.map +1 -0
- package/build/config/config.module.js +49 -0
- package/build/config/config.module.js.map +1 -0
- package/build/config/config.service.d.ts +74 -0
- package/build/config/config.service.d.ts.map +1 -0
- package/build/config/config.service.js +145 -0
- package/build/config/config.service.js.map +1 -0
- package/build/config/config.types.d.ts +143 -0
- package/build/config/config.types.d.ts.map +1 -0
- package/build/config/config.types.js +2 -0
- package/build/config/config.types.js.map +1 -0
- package/build/config/decorators/config.decorators.d.ts +43 -0
- package/build/config/decorators/config.decorators.d.ts.map +1 -0
- package/build/config/decorators/config.decorators.js +68 -0
- package/build/config/decorators/config.decorators.js.map +1 -0
- package/build/config/decorators/index.d.ts +2 -0
- package/build/config/decorators/index.d.ts.map +1 -0
- package/build/config/decorators/index.js +2 -0
- package/build/config/decorators/index.js.map +1 -0
- package/build/config/index.d.ts +7 -0
- package/build/config/index.d.ts.map +1 -0
- package/build/config/index.js +9 -0
- package/build/config/index.js.map +1 -0
- package/build/config/validation.utils.d.ts +136 -0
- package/build/config/validation.utils.d.ts.map +1 -0
- package/build/config/validation.utils.js +263 -0
- package/build/config/validation.utils.js.map +1 -0
- package/build/errors/index.d.ts +9 -0
- package/build/errors/index.d.ts.map +1 -0
- package/build/errors/index.js +12 -0
- package/build/errors/index.js.map +1 -0
- package/build/guards/custom-throttle.guard.d.ts +28 -0
- package/build/guards/custom-throttle.guard.d.ts.map +1 -0
- package/build/guards/custom-throttle.guard.js +52 -0
- package/build/guards/custom-throttle.guard.js.map +1 -0
- package/build/guards/index.d.ts +2 -0
- package/build/guards/index.d.ts.map +1 -0
- package/build/guards/index.js +2 -0
- package/build/guards/index.js.map +1 -0
- package/build/index.d.ts +53 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +61 -0
- package/build/index.js.map +1 -0
- package/build/logging/index.d.ts +7 -0
- package/build/logging/index.d.ts.map +1 -0
- package/build/logging/index.js +7 -0
- package/build/logging/index.js.map +1 -0
- package/build/metrics/index.d.ts +6 -0
- package/build/metrics/index.d.ts.map +1 -0
- package/build/metrics/index.js +11 -0
- package/build/metrics/index.js.map +1 -0
- package/build/package.json +72 -0
- package/build/security/index.d.ts +8 -0
- package/build/security/index.d.ts.map +1 -0
- package/build/security/index.js +11 -0
- package/build/security/index.js.map +1 -0
- package/build/test-setup.d.ts +2 -0
- package/build/test-setup.d.ts.map +1 -0
- package/build/test-setup.js +40 -0
- package/build/test-setup.js.map +1 -0
- package/build/validation/index.d.ts +6 -0
- package/build/validation/index.d.ts.map +1 -0
- package/build/validation/index.js +8 -0
- package/build/validation/index.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { HTTP_STATUS_INTERNAL_SERVER_ERROR } from '../constants/http-status.constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Base Application Error
|
|
4
|
+
*
|
|
5
|
+
* Provides a standardized error structure for NestJS applications with consistent
|
|
6
|
+
* properties and methods for error handling, serialization, and context management.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* throw new BaseApplicationError('User not found', {
|
|
11
|
+
* code: 'USER_NOT_FOUND',
|
|
12
|
+
* statusCode: 404,
|
|
13
|
+
* context: { userId: '123' }
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export class BaseApplicationError extends Error {
|
|
18
|
+
/**
|
|
19
|
+
* The HTTP status code associated with this error
|
|
20
|
+
*/
|
|
21
|
+
statusCode;
|
|
22
|
+
/**
|
|
23
|
+
* The error code for programmatic error identification
|
|
24
|
+
*/
|
|
25
|
+
code;
|
|
26
|
+
/**
|
|
27
|
+
* Additional context information for debugging and logging
|
|
28
|
+
*/
|
|
29
|
+
context;
|
|
30
|
+
/**
|
|
31
|
+
* Timestamp when the error was created
|
|
32
|
+
*/
|
|
33
|
+
timestamp;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new BaseApplicationError instance
|
|
36
|
+
*
|
|
37
|
+
* @param message - The error message
|
|
38
|
+
* @param options - Configuration options for the error
|
|
39
|
+
* @param options.code - The error code (defaults to 'INTERNAL_SERVER_ERROR')
|
|
40
|
+
* @param options.statusCode - The HTTP status code (defaults to 500)
|
|
41
|
+
* @param options.context - Additional context information (defaults to empty object)
|
|
42
|
+
*/
|
|
43
|
+
constructor(message, options = {}) {
|
|
44
|
+
super(message);
|
|
45
|
+
const { code = 'INTERNAL_SERVER_ERROR', statusCode = HTTP_STATUS_INTERNAL_SERVER_ERROR, context = {} } = options;
|
|
46
|
+
this.name = this.constructor.name;
|
|
47
|
+
this.statusCode = statusCode;
|
|
48
|
+
this.code = code;
|
|
49
|
+
this.context = { ...context };
|
|
50
|
+
this.timestamp = new Date();
|
|
51
|
+
// Capture stack trace
|
|
52
|
+
if (Error.captureStackTrace) {
|
|
53
|
+
Error.captureStackTrace(this, this.constructor);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Serializes the error to a plain object for JSON responses or logging
|
|
58
|
+
*
|
|
59
|
+
* @returns A plain object representation of the error
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const error = new BaseApplicationError('Test error');
|
|
64
|
+
* console.log(error.toJSON());
|
|
65
|
+
* // {
|
|
66
|
+
* // name: 'BaseApplicationError',
|
|
67
|
+
* // message: 'Test error',
|
|
68
|
+
* // code: 'INTERNAL_SERVER_ERROR',
|
|
69
|
+
* // statusCode: 500,
|
|
70
|
+
* // context: {},
|
|
71
|
+
* // timestamp: '2023-01-01T00:00:00.000Z'
|
|
72
|
+
* // }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
toJSON() {
|
|
76
|
+
return {
|
|
77
|
+
name: this.name,
|
|
78
|
+
message: this.message,
|
|
79
|
+
code: this.code,
|
|
80
|
+
statusCode: this.statusCode,
|
|
81
|
+
context: this.context,
|
|
82
|
+
timestamp: this.timestamp.toISOString(),
|
|
83
|
+
// Include stack trace in development
|
|
84
|
+
...(process.env['NODE_ENV'] !== 'production' ? { stack: this.stack } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new error instance with additional context merged into the existing context.
|
|
89
|
+
* Note: Returns a new instance, not the same instance, so instanceof checks will still work.
|
|
90
|
+
*
|
|
91
|
+
* @param additionalContext - Additional context to merge
|
|
92
|
+
* @returns A new error instance of the same type with merged context
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const error = new BaseApplicationError('User error', { code: 'USER_ERROR' });
|
|
97
|
+
* const errorWithContext = error.withContext({ userId: '123', action: 'login' });
|
|
98
|
+
* // errorWithContext is a new instance but still instanceof BaseApplicationError
|
|
99
|
+
* // errorWithContext.context = { userId: '123', action: 'login' }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
withContext(additionalContext) {
|
|
103
|
+
const mergedContext = { ...this.context, ...additionalContext };
|
|
104
|
+
const Constructor = this.constructor;
|
|
105
|
+
return new Constructor(this.message, {
|
|
106
|
+
code: this.code,
|
|
107
|
+
statusCode: this.statusCode,
|
|
108
|
+
context: mergedContext,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Creates a new error instance with a different message
|
|
113
|
+
*
|
|
114
|
+
* @param newMessage - The new error message
|
|
115
|
+
* @returns A new error instance with the updated message
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const error = new BaseApplicationError('Generic error');
|
|
120
|
+
* const specificError = error.withMessage('User not found');
|
|
121
|
+
* // specificError.message = 'User not found'
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
withMessage(newMessage) {
|
|
125
|
+
const Constructor = this.constructor;
|
|
126
|
+
return new Constructor(newMessage, {
|
|
127
|
+
code: this.code,
|
|
128
|
+
statusCode: this.statusCode,
|
|
129
|
+
context: this.context,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=base-application-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-application-error.js","sourceRoot":"","sources":["../../../src/common/errors/base-application-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC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AAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1E,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACI,WAAW,CAAC,iBAAsC;QACxD,MAAM,aAAa,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,iBAAiB,EAAE,CAAC;QAChE,MAAM,WAAW,GAAG,IAAI,CAAC,WAGhB,CAAC;QAEV,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE;YACpC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,aAAa;SACtB,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;OAYG;IACI,WAAW,CAAC,UAAkB;QACpC,MAAM,WAAW,GAAG,IAAI,CAAC,WAGhB,CAAC;QAEV,OAAO,IAAI,WAAW,CAAC,UAAU,EAAE;YAClC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { BaseApplicationError } from './base-application-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration interface for creating error classes
|
|
4
|
+
*/
|
|
5
|
+
export interface ErrorConfig {
|
|
6
|
+
/** The error code for programmatic identification */
|
|
7
|
+
code: string;
|
|
8
|
+
/** The HTTP status code */
|
|
9
|
+
statusCode: number;
|
|
10
|
+
/** Default error message */
|
|
11
|
+
defaultMessage: string;
|
|
12
|
+
/** Optional error class name (defaults to code + 'Error') */
|
|
13
|
+
name?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Factory function to create application error classes
|
|
17
|
+
*
|
|
18
|
+
* This factory eliminates code duplication by generating error classes
|
|
19
|
+
* from configuration objects instead of defining each class individually.
|
|
20
|
+
*
|
|
21
|
+
* @param config - Configuration for the error class
|
|
22
|
+
* @returns An application error class constructor
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* export const NotFoundError = createError({
|
|
27
|
+
* code: 'NOT_FOUND',
|
|
28
|
+
* statusCode: 404,
|
|
29
|
+
* defaultMessage: 'Resource not found'
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function createError(config: ErrorConfig): typeof BaseApplicationError;
|
|
34
|
+
/**
|
|
35
|
+
* Error configurations for all standard HTTP error types
|
|
36
|
+
*/
|
|
37
|
+
export declare const ERROR_CONFIGS: {
|
|
38
|
+
readonly BAD_REQUEST: {
|
|
39
|
+
readonly code: "BAD_REQUEST";
|
|
40
|
+
readonly statusCode: 400;
|
|
41
|
+
readonly defaultMessage: "Bad request";
|
|
42
|
+
};
|
|
43
|
+
readonly UNAUTHORIZED: {
|
|
44
|
+
readonly code: "UNAUTHORIZED";
|
|
45
|
+
readonly statusCode: 401;
|
|
46
|
+
readonly defaultMessage: "Unauthorized";
|
|
47
|
+
};
|
|
48
|
+
readonly FORBIDDEN: {
|
|
49
|
+
readonly code: "FORBIDDEN";
|
|
50
|
+
readonly statusCode: 403;
|
|
51
|
+
readonly defaultMessage: "Forbidden";
|
|
52
|
+
};
|
|
53
|
+
readonly NOT_FOUND: {
|
|
54
|
+
readonly code: "NOT_FOUND";
|
|
55
|
+
readonly statusCode: 404;
|
|
56
|
+
readonly defaultMessage: "Not found";
|
|
57
|
+
};
|
|
58
|
+
readonly CONFLICT: {
|
|
59
|
+
readonly code: "CONFLICT";
|
|
60
|
+
readonly statusCode: 409;
|
|
61
|
+
readonly defaultMessage: "Conflict";
|
|
62
|
+
};
|
|
63
|
+
readonly UNPROCESSABLE_ENTITY: {
|
|
64
|
+
readonly code: "UNPROCESSABLE_ENTITY";
|
|
65
|
+
readonly statusCode: 422;
|
|
66
|
+
readonly defaultMessage: "Unprocessable entity";
|
|
67
|
+
};
|
|
68
|
+
readonly INTERNAL_SERVER_ERROR: {
|
|
69
|
+
readonly code: "INTERNAL_SERVER_ERROR";
|
|
70
|
+
readonly statusCode: 500;
|
|
71
|
+
readonly defaultMessage: "Internal server error";
|
|
72
|
+
};
|
|
73
|
+
readonly BAD_GATEWAY: {
|
|
74
|
+
readonly code: "BAD_GATEWAY";
|
|
75
|
+
readonly statusCode: 502;
|
|
76
|
+
readonly defaultMessage: "Bad gateway";
|
|
77
|
+
};
|
|
78
|
+
readonly SERVICE_UNAVAILABLE: {
|
|
79
|
+
readonly code: "SERVICE_UNAVAILABLE";
|
|
80
|
+
readonly statusCode: 503;
|
|
81
|
+
readonly defaultMessage: "Service unavailable";
|
|
82
|
+
};
|
|
83
|
+
readonly GATEWAY_TIMEOUT: {
|
|
84
|
+
readonly code: "GATEWAY_TIMEOUT";
|
|
85
|
+
readonly statusCode: 504;
|
|
86
|
+
readonly defaultMessage: "Gateway timeout";
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Type for error configuration keys
|
|
91
|
+
*/
|
|
92
|
+
export type ErrorType = keyof typeof ERROR_CONFIGS;
|
|
93
|
+
//# sourceMappingURL=error-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-factory.d.ts","sourceRoot":"","sources":["../../../src/common/errors/error-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,4BAA4B;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,oBAAoB,CAgC5E;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDhB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,aAAa,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { BaseApplicationError } from './base-application-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Factory function to create application error classes
|
|
4
|
+
*
|
|
5
|
+
* This factory eliminates code duplication by generating error classes
|
|
6
|
+
* from configuration objects instead of defining each class individually.
|
|
7
|
+
*
|
|
8
|
+
* @param config - Configuration for the error class
|
|
9
|
+
* @returns An application error class constructor
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* export const NotFoundError = createError({
|
|
14
|
+
* code: 'NOT_FOUND',
|
|
15
|
+
* statusCode: 404,
|
|
16
|
+
* defaultMessage: 'Resource not found'
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function createError(config) {
|
|
21
|
+
const { code, statusCode, defaultMessage, name = `${code}Error` } = config;
|
|
22
|
+
/**
|
|
23
|
+
* Dynamically created application error class
|
|
24
|
+
*/
|
|
25
|
+
class GeneratedApplicationError extends BaseApplicationError {
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new error instance
|
|
28
|
+
*
|
|
29
|
+
* @param message - Custom error message (optional)
|
|
30
|
+
* @param context - Additional context information (optional)
|
|
31
|
+
*/
|
|
32
|
+
constructor(message = defaultMessage, context) {
|
|
33
|
+
const options = {
|
|
34
|
+
code,
|
|
35
|
+
statusCode,
|
|
36
|
+
};
|
|
37
|
+
if (context !== undefined) {
|
|
38
|
+
options.context = context;
|
|
39
|
+
}
|
|
40
|
+
super(message, options);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Set the class name for better debugging and instanceof checks
|
|
44
|
+
Object.defineProperty(GeneratedApplicationError, 'name', {
|
|
45
|
+
value: name,
|
|
46
|
+
writable: false,
|
|
47
|
+
});
|
|
48
|
+
return GeneratedApplicationError;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Error configurations for all standard HTTP error types
|
|
52
|
+
*/
|
|
53
|
+
export const ERROR_CONFIGS = {
|
|
54
|
+
BAD_REQUEST: {
|
|
55
|
+
code: 'BAD_REQUEST',
|
|
56
|
+
statusCode: 400,
|
|
57
|
+
defaultMessage: 'Bad request',
|
|
58
|
+
},
|
|
59
|
+
UNAUTHORIZED: {
|
|
60
|
+
code: 'UNAUTHORIZED',
|
|
61
|
+
statusCode: 401,
|
|
62
|
+
defaultMessage: 'Unauthorized',
|
|
63
|
+
},
|
|
64
|
+
FORBIDDEN: {
|
|
65
|
+
code: 'FORBIDDEN',
|
|
66
|
+
statusCode: 403,
|
|
67
|
+
defaultMessage: 'Forbidden',
|
|
68
|
+
},
|
|
69
|
+
NOT_FOUND: {
|
|
70
|
+
code: 'NOT_FOUND',
|
|
71
|
+
statusCode: 404,
|
|
72
|
+
defaultMessage: 'Not found',
|
|
73
|
+
},
|
|
74
|
+
CONFLICT: {
|
|
75
|
+
code: 'CONFLICT',
|
|
76
|
+
statusCode: 409,
|
|
77
|
+
defaultMessage: 'Conflict',
|
|
78
|
+
},
|
|
79
|
+
UNPROCESSABLE_ENTITY: {
|
|
80
|
+
code: 'UNPROCESSABLE_ENTITY',
|
|
81
|
+
statusCode: 422,
|
|
82
|
+
defaultMessage: 'Unprocessable entity',
|
|
83
|
+
},
|
|
84
|
+
INTERNAL_SERVER_ERROR: {
|
|
85
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
86
|
+
statusCode: 500,
|
|
87
|
+
defaultMessage: 'Internal server error',
|
|
88
|
+
},
|
|
89
|
+
BAD_GATEWAY: {
|
|
90
|
+
code: 'BAD_GATEWAY',
|
|
91
|
+
statusCode: 502,
|
|
92
|
+
defaultMessage: 'Bad gateway',
|
|
93
|
+
},
|
|
94
|
+
SERVICE_UNAVAILABLE: {
|
|
95
|
+
code: 'SERVICE_UNAVAILABLE',
|
|
96
|
+
statusCode: 503,
|
|
97
|
+
defaultMessage: 'Service unavailable',
|
|
98
|
+
},
|
|
99
|
+
GATEWAY_TIMEOUT: {
|
|
100
|
+
code: 'GATEWAY_TIMEOUT',
|
|
101
|
+
statusCode: 504,
|
|
102
|
+
defaultMessage: 'Gateway timeout',
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=error-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-factory.js","sourceRoot":"","sources":["../../../src/common/errors/error-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAgBnE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC9C,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,GAAG,GAAG,IAAI,OAAO,EAAE,GAAG,MAAM,CAAC;IAE3E;;OAEG;IACH,MAAM,yBAA0B,SAAQ,oBAAoB;QAC3D;;;;;WAKG;QACH,YAAY,OAAO,GAAG,cAAc,EAAE,OAA6B;YAClE,MAAM,OAAO,GAAQ;gBACpB,IAAI;gBACJ,UAAU;aACV,CAAC;YACF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC3B,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;YAC3B,CAAC;YACD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACzB,CAAC;KACD;IAED,gEAAgE;IAChE,MAAM,CAAC,cAAc,CAAC,yBAAyB,EAAE,MAAM,EAAE;QACxD,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,KAAK;KACf,CAAC,CAAC;IAEH,OAAO,yBAAyB,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,WAAW,EAAE;QACZ,IAAI,EAAE,aAAa;QACnB,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,aAAa;KAC7B;IACD,YAAY,EAAE;QACb,IAAI,EAAE,cAAc;QACpB,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,cAAc;KAC9B;IACD,SAAS,EAAE;QACV,IAAI,EAAE,WAAW;QACjB,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,WAAW;KAC3B;IACD,SAAS,EAAE;QACV,IAAI,EAAE,WAAW;QACjB,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,WAAW;KAC3B;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,UAAU;QAChB,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,UAAU;KAC1B;IACD,oBAAoB,EAAE;QACrB,IAAI,EAAE,sBAAsB;QAC5B,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,sBAAsB;KACtC;IACD,qBAAqB,EAAE;QACtB,IAAI,EAAE,uBAAuB;QAC7B,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,uBAAuB;KACvC;IACD,WAAW,EAAE;QACZ,IAAI,EAAE,aAAa;QACnB,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,aAAa;KAC7B;IACD,mBAAmB,EAAE;QACpB,IAAI,EAAE,qBAAqB;QAC3B,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,qBAAqB;KACrC;IACD,eAAe,EAAE;QAChB,IAAI,EAAE,iBAAiB;QACvB,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,iBAAiB;KACjC;CACQ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { BaseApplicationError } from './base-application-error.js';
|
|
2
|
+
export { createError, ERROR_CONFIGS, type ErrorConfig, type ErrorType } from './error-factory.js';
|
|
3
|
+
export declare const BadRequestError: typeof import("./base-application-error.js").BaseApplicationError;
|
|
4
|
+
export declare const UnauthorizedError: typeof import("./base-application-error.js").BaseApplicationError;
|
|
5
|
+
export declare const ForbiddenError: typeof import("./base-application-error.js").BaseApplicationError;
|
|
6
|
+
export declare const NotFoundError: typeof import("./base-application-error.js").BaseApplicationError;
|
|
7
|
+
export declare const ConflictError: typeof import("./base-application-error.js").BaseApplicationError;
|
|
8
|
+
export declare const UnprocessableEntityError: typeof import("./base-application-error.js").BaseApplicationError;
|
|
9
|
+
export declare const InternalServerError: typeof import("./base-application-error.js").BaseApplicationError;
|
|
10
|
+
export declare const BadGatewayError: typeof import("./base-application-error.js").BaseApplicationError;
|
|
11
|
+
export declare const ServiceUnavailableError: typeof import("./base-application-error.js").BaseApplicationError;
|
|
12
|
+
export declare const GatewayTimeoutError: typeof import("./base-application-error.js").BaseApplicationError;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKlG,eAAO,MAAM,eAAe,mEAAyC,CAAC;AACtE,eAAO,MAAM,iBAAiB,mEAA0C,CAAC;AACzE,eAAO,MAAM,cAAc,mEAAuC,CAAC;AACnE,eAAO,MAAM,aAAa,mEAAuC,CAAC;AAClE,eAAO,MAAM,aAAa,mEAAsC,CAAC;AACjE,eAAO,MAAM,wBAAwB,mEAAkD,CAAC;AACxF,eAAO,MAAM,mBAAmB,mEAAmD,CAAC;AACpF,eAAO,MAAM,eAAe,mEAAyC,CAAC;AACtE,eAAO,MAAM,uBAAuB,mEAAiD,CAAC;AACtF,eAAO,MAAM,mBAAmB,mEAA6C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { BaseApplicationError } from './base-application-error.js';
|
|
2
|
+
export { createError, ERROR_CONFIGS } from './error-factory.js';
|
|
3
|
+
import { createError, ERROR_CONFIGS } from './error-factory.js';
|
|
4
|
+
// Predefined error classes
|
|
5
|
+
export const BadRequestError = createError(ERROR_CONFIGS.BAD_REQUEST);
|
|
6
|
+
export const UnauthorizedError = createError(ERROR_CONFIGS.UNAUTHORIZED);
|
|
7
|
+
export const ForbiddenError = createError(ERROR_CONFIGS.FORBIDDEN);
|
|
8
|
+
export const NotFoundError = createError(ERROR_CONFIGS.NOT_FOUND);
|
|
9
|
+
export const ConflictError = createError(ERROR_CONFIGS.CONFLICT);
|
|
10
|
+
export const UnprocessableEntityError = createError(ERROR_CONFIGS.UNPROCESSABLE_ENTITY);
|
|
11
|
+
export const InternalServerError = createError(ERROR_CONFIGS.INTERNAL_SERVER_ERROR);
|
|
12
|
+
export const BadGatewayError = createError(ERROR_CONFIGS.BAD_GATEWAY);
|
|
13
|
+
export const ServiceUnavailableError = createError(ERROR_CONFIGS.SERVICE_UNAVAILABLE);
|
|
14
|
+
export const GatewayTimeoutError = createError(ERROR_CONFIGS.GATEWAY_TIMEOUT);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAoC,MAAM,oBAAoB,CAAC;AAElG,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEhE,2BAA2B;AAC3B,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;AACtE,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;AACzE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;AAClE,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC;AACxF,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;AACtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,WAAW,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC;AACtF,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ApplySecurityMiddleware } from './security-bootstrap.factory.js';
|
|
2
|
+
export type { SecurityBootstrapOptions } from './security-bootstrap.factory.js';
|
|
3
|
+
export { CreateRateLimitConfig } from './rate-limit-config.factory.js';
|
|
4
|
+
export type { RateLimitConfig, RateLimitDescriptor } from './rate-limit-config.factory.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/factories/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,YAAY,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/factories/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module factory utilities for common NestJS module patterns
|
|
3
|
+
*
|
|
4
|
+
* Provides standardized factory functions for creating modules with consistent
|
|
5
|
+
* structure, providers, exports, and configuration patterns.
|
|
6
|
+
*/
|
|
7
|
+
import { DynamicModule } from '@nestjs/common';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration interface for global modules
|
|
10
|
+
*/
|
|
11
|
+
export interface GlobalModuleConfig {
|
|
12
|
+
/** Module name for logging */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Providers to include in the module */
|
|
15
|
+
providers?: any[];
|
|
16
|
+
/** Services to export from the module */
|
|
17
|
+
exports?: any[];
|
|
18
|
+
/** Other modules to import */
|
|
19
|
+
imports?: any[];
|
|
20
|
+
/** Whether the module is global (default: true) */
|
|
21
|
+
isGlobal?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configuration interface for feature modules
|
|
25
|
+
*/
|
|
26
|
+
export interface FeatureModuleConfig {
|
|
27
|
+
/** Module name for logging */
|
|
28
|
+
name: string;
|
|
29
|
+
/** Providers to include in the module */
|
|
30
|
+
providers?: any[];
|
|
31
|
+
/** Services to export from the module */
|
|
32
|
+
exports?: any[];
|
|
33
|
+
/** Controllers to include */
|
|
34
|
+
controllers?: any[];
|
|
35
|
+
/** Other modules to import */
|
|
36
|
+
imports?: any[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Configuration interface for service modules
|
|
40
|
+
*/
|
|
41
|
+
export interface ServiceModuleConfig {
|
|
42
|
+
/** Module name for logging */
|
|
43
|
+
name: string;
|
|
44
|
+
/** Service providers */
|
|
45
|
+
providers?: any[];
|
|
46
|
+
/** Services to export */
|
|
47
|
+
exports?: any[];
|
|
48
|
+
/** Other modules to import */
|
|
49
|
+
imports?: any[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Configuration interface for application modules
|
|
53
|
+
*/
|
|
54
|
+
export interface ApplicationModuleConfig {
|
|
55
|
+
/** Module name for logging */
|
|
56
|
+
name: string;
|
|
57
|
+
/** Global filters to apply */
|
|
58
|
+
filters?: any[];
|
|
59
|
+
/** Global interceptors to apply */
|
|
60
|
+
interceptors?: any[];
|
|
61
|
+
/** Global pipes to apply */
|
|
62
|
+
pipes?: any[];
|
|
63
|
+
/** Global guards to apply */
|
|
64
|
+
guards?: any[];
|
|
65
|
+
/** Other modules to import */
|
|
66
|
+
imports?: any[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates a global module with standardized configuration
|
|
70
|
+
*
|
|
71
|
+
* @param config - Module configuration
|
|
72
|
+
* @returns DynamicModule
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* @Module({})
|
|
77
|
+
* export class ConfigModule extends createGlobalModule({
|
|
78
|
+
* name: 'ConfigModule',
|
|
79
|
+
* providers: [ConfigService],
|
|
80
|
+
* exports: [ConfigService],
|
|
81
|
+
* }) {}
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function CreateGlobalModule(config: GlobalModuleConfig): DynamicModule;
|
|
85
|
+
/**
|
|
86
|
+
* Creates a feature module with standardized configuration
|
|
87
|
+
*
|
|
88
|
+
* @param config - Module configuration
|
|
89
|
+
* @returns DynamicModule
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* @Module({})
|
|
94
|
+
* export class UserModule extends createFeatureModule({
|
|
95
|
+
* name: 'UserModule',
|
|
96
|
+
* controllers: [UserController],
|
|
97
|
+
* providers: [UserService],
|
|
98
|
+
* exports: [UserService],
|
|
99
|
+
* }) {}
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function CreateFeatureModule(config: FeatureModuleConfig): DynamicModule;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a service module with standardized configuration
|
|
105
|
+
*
|
|
106
|
+
* @param config - Module configuration
|
|
107
|
+
* @returns DynamicModule
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* @Module({})
|
|
112
|
+
* export class DatabaseModule extends createServiceModule({
|
|
113
|
+
* name: 'DatabaseModule',
|
|
114
|
+
* providers: [DatabaseService, DatabaseConnection],
|
|
115
|
+
* exports: [DatabaseService],
|
|
116
|
+
* }) {}
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function CreateServiceModule(config: ServiceModuleConfig): DynamicModule;
|
|
120
|
+
/**
|
|
121
|
+
* Creates an application module with global filters, interceptors, pipes, and guards
|
|
122
|
+
*
|
|
123
|
+
* @param config - Module configuration
|
|
124
|
+
* @returns DynamicModule
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* @Module({})
|
|
129
|
+
* export class AppModule extends createApplicationModule({
|
|
130
|
+
* name: 'AppModule',
|
|
131
|
+
* imports: [UserModule, AuthModule],
|
|
132
|
+
* filters: [HttpExceptionFilter],
|
|
133
|
+
* interceptors: [LoggingInterceptor],
|
|
134
|
+
* pipes: [ValidationPipe],
|
|
135
|
+
* guards: [AuthGuard],
|
|
136
|
+
* }) {}
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function CreateApplicationModule(config: ApplicationModuleConfig): DynamicModule;
|
|
140
|
+
/**
|
|
141
|
+
* Creates a module with conditional providers based on configuration
|
|
142
|
+
*
|
|
143
|
+
* @param config - Base module configuration
|
|
144
|
+
* @param conditions - Array of conditional provider configurations
|
|
145
|
+
* @returns DynamicModule
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* @Module({})
|
|
150
|
+
* export class CacheModule extends createConditionalModule(
|
|
151
|
+
* { name: 'CacheModule', imports: [ConfigModule] },
|
|
152
|
+
* [
|
|
153
|
+
* {
|
|
154
|
+
* condition: (config) => config.get('CACHE_ENABLED'),
|
|
155
|
+
* providers: [RedisService],
|
|
156
|
+
* exports: [RedisService],
|
|
157
|
+
* },
|
|
158
|
+
* ]
|
|
159
|
+
* ) {}
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export declare function CreateConditionalModule(baseConfig: Partial<GlobalModuleConfig & FeatureModuleConfig & ServiceModuleConfig>, conditions: Array<{
|
|
163
|
+
condition: (config?: any) => boolean;
|
|
164
|
+
providers?: any[];
|
|
165
|
+
exports?: any[];
|
|
166
|
+
imports?: any[];
|
|
167
|
+
controllers?: any[];
|
|
168
|
+
config?: any;
|
|
169
|
+
}>): DynamicModule;
|
|
170
|
+
/**
|
|
171
|
+
* Backwards compatibility aliases - exported functions use PascalCase per project conventions
|
|
172
|
+
*/
|
|
173
|
+
export declare const createApplicationModule: typeof CreateApplicationModule;
|
|
174
|
+
export declare const createConditionalModule: typeof CreateConditionalModule;
|
|
175
|
+
export declare const createFeatureModule: typeof CreateFeatureModule;
|
|
176
|
+
export declare const createGlobalModule: typeof CreateGlobalModule;
|
|
177
|
+
export declare const createServiceModule: typeof CreateServiceModule;
|
|
178
|
+
//# sourceMappingURL=module-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-factory.d.ts","sourceRoot":"","sources":["../../../src/common/factories/module-factory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAU,MAAM,gBAAgB,CAAC;AAGvD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,SAAS,CAAC,EAAE,GAAG,EAAE,CA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