@pawells/nestjs-shared 1.0.0-dev.3052c75
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 @@
|
|
|
1
|
+
{"version":3,"file":"common-decorators.d.ts","sourceRoot":"","sources":["../../../src/common/decorators/common-decorators.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAItD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAIvD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAIrD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAIxD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAIxD"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { CreateRequestPropertyDecorator } from './decorator-factory.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extract query parameters from HTTP request.
|
|
4
|
+
* @param key - Specific query parameter key (optional - extracts all if not specified)
|
|
5
|
+
* @returns Parameter decorator
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Extract all query parameters
|
|
10
|
+
* @Get()
|
|
11
|
+
* getData(@Query() query: any) {}
|
|
12
|
+
*
|
|
13
|
+
* // Extract specific query parameter
|
|
14
|
+
* @Get()
|
|
15
|
+
* getData(@Query('limit') limit: number) {}
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function Query(key) {
|
|
19
|
+
return CreateRequestPropertyDecorator((request) => (key ? request.query[key] : request.query));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Extract route parameters from HTTP request.
|
|
23
|
+
* @param key - Specific route parameter key (optional - extracts all if not specified)
|
|
24
|
+
* @returns Parameter decorator
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // Extract all route parameters
|
|
29
|
+
* @Get(':id')
|
|
30
|
+
* getUser(@Params() params: any) {}
|
|
31
|
+
*
|
|
32
|
+
* // Extract specific route parameter
|
|
33
|
+
* @Get(':id')
|
|
34
|
+
* getUser(@Params('id') id: string) {}
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function Params(key) {
|
|
38
|
+
return CreateRequestPropertyDecorator((request) => (key ? request.params[key] : request.params));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Extract request body from HTTP request.
|
|
42
|
+
* @param key - Specific body property key (optional - extracts all if not specified)
|
|
43
|
+
* @returns Parameter decorator
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Extract entire body
|
|
48
|
+
* @Post()
|
|
49
|
+
* createUser(@Body() userData: CreateUserDto) {}
|
|
50
|
+
*
|
|
51
|
+
* // Extract specific body property
|
|
52
|
+
* @Patch(':id')
|
|
53
|
+
* updateUser(@Body('email') email: string) {}
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export function Body(key) {
|
|
57
|
+
return CreateRequestPropertyDecorator((request) => (key ? request.body[key] : request.body));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Extract request headers from HTTP request.
|
|
61
|
+
* @param key - Specific header key (optional - extracts all if not specified)
|
|
62
|
+
* @returns Parameter decorator
|
|
63
|
+
*
|
|
64
|
+
* @remarks Header names are case-insensitive in HTTP/1.1.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Extract all headers
|
|
69
|
+
* @Get()
|
|
70
|
+
* getData(@Headers() headers: any) {}
|
|
71
|
+
*
|
|
72
|
+
* // Extract specific header
|
|
73
|
+
* @Get()
|
|
74
|
+
* getData(@Headers('authorization') auth: string) {}
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function Headers(key) {
|
|
78
|
+
return CreateRequestPropertyDecorator((request) => (key ? request.headers[key] : request.headers));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Extract cookies from HTTP request.
|
|
82
|
+
* @param key - Specific cookie key (optional - extracts all if not specified)
|
|
83
|
+
* @returns Parameter decorator
|
|
84
|
+
*
|
|
85
|
+
* @remarks Requires cookie-parser middleware to be enabled.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // Extract all cookies
|
|
90
|
+
* @Get()
|
|
91
|
+
* getData(@Cookies() cookies: any) {}
|
|
92
|
+
*
|
|
93
|
+
* // Extract specific cookie
|
|
94
|
+
* @Get()
|
|
95
|
+
* getData(@Cookies('sessionId') sessionId: string) {}
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export function Cookies(key) {
|
|
99
|
+
return CreateRequestPropertyDecorator((request) => (key ? request.cookies[key] : request.cookies));
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=common-decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common-decorators.js","sourceRoot":"","sources":["../../../src/common/decorators/common-decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAExE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,KAAK,CAAC,GAAY;IACjC,OAAO,8BAA8B,CACpC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CACvD,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,MAAM,CAAC,GAAY;IAClC,OAAO,8BAA8B,CACpC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CACzD,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,IAAI,CAAC,GAAY;IAChC,OAAO,8BAA8B,CACpC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CACrD,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,OAAO,CAAC,GAAY;IACnC,OAAO,8BAA8B,CACpC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAC3D,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,OAAO,CAAC,GAAY;IACnC,OAAO,8BAA8B,CACpC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAC3D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import type { Request } from 'express';
|
|
3
|
+
/**
|
|
4
|
+
* Base options for decorator factories
|
|
5
|
+
*/
|
|
6
|
+
export interface BaseDecoratorOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Transform function to apply to the extracted value
|
|
9
|
+
*/
|
|
10
|
+
transform?: (value: unknown) => unknown;
|
|
11
|
+
/**
|
|
12
|
+
* Validation function to check the extracted value
|
|
13
|
+
*/
|
|
14
|
+
validate?: (value: unknown) => boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for conditional decorators (metadata-based)
|
|
18
|
+
*/
|
|
19
|
+
export interface ConditionalDecoratorOptions extends BaseDecoratorOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Metadata key to set
|
|
22
|
+
*/
|
|
23
|
+
key: string;
|
|
24
|
+
/**
|
|
25
|
+
* Metadata value to set
|
|
26
|
+
*/
|
|
27
|
+
value: any;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for validating decorators
|
|
31
|
+
*/
|
|
32
|
+
export interface ValidatingDecoratorOptions extends BaseDecoratorOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Whether to throw an error if validation fails
|
|
35
|
+
*/
|
|
36
|
+
throwOnInvalid?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Error message for validation failures
|
|
39
|
+
*/
|
|
40
|
+
errorMessage?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for transforming decorators
|
|
44
|
+
*/
|
|
45
|
+
export interface TransformingDecoratorOptions extends BaseDecoratorOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Whether to apply transformation even if value is undefined/null
|
|
48
|
+
*/
|
|
49
|
+
transformUndefined?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Gets the request object from HTTP execution context
|
|
53
|
+
* @param ctx - The execution context
|
|
54
|
+
* @returns The request object
|
|
55
|
+
*/
|
|
56
|
+
export declare function GetRequestFromContext(ctx: ExecutionContext): Request;
|
|
57
|
+
/**
|
|
58
|
+
* Base factory for creating parameter decorators that extend RequestProperty functionality
|
|
59
|
+
* @param extractor - Function that extracts the value from request
|
|
60
|
+
* @param options - Configuration options
|
|
61
|
+
* @returns Parameter decorator function
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // With explicit type parameter
|
|
65
|
+
* const MyDecorator = CreateRequestPropertyDecorator<string>(
|
|
66
|
+
* (req) => req.headers['x-custom-id'],
|
|
67
|
+
* { transform: (v) => (v as string).toUpperCase() }
|
|
68
|
+
* );
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function CreateRequestPropertyDecorator<T = any>(extractor: (request: Request, ctx: ExecutionContext) => T, options?: BaseDecoratorOptions): ParameterDecorator;
|
|
72
|
+
/**
|
|
73
|
+
* Factory for creating conditional decorators that set metadata
|
|
74
|
+
* @param options - Configuration options
|
|
75
|
+
* @returns Method decorator function
|
|
76
|
+
*/
|
|
77
|
+
export declare function CreateConditionalDecorator(options: ConditionalDecoratorOptions): MethodDecorator;
|
|
78
|
+
/**
|
|
79
|
+
* Factory for creating validating decorators
|
|
80
|
+
* @param extractor - Function that extracts the value from request
|
|
81
|
+
* @param options - Configuration options
|
|
82
|
+
* @returns Parameter decorator function
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* // With explicit type parameter
|
|
86
|
+
* const ValidatedId = CreateValidatingDecorator<string>(
|
|
87
|
+
* (req) => req.params.id,
|
|
88
|
+
* { validate: (v) => typeof v === 'string' && v.length > 0 }
|
|
89
|
+
* );
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function CreateValidatingDecorator<T = any>(extractor: (request: Request, ctx: ExecutionContext) => T, options?: ValidatingDecoratorOptions): ParameterDecorator;
|
|
93
|
+
/**
|
|
94
|
+
* Factory for creating transforming decorators
|
|
95
|
+
* @param extractor - Function that extracts the value from request
|
|
96
|
+
* @param options - Configuration options
|
|
97
|
+
* @returns Parameter decorator function
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // With explicit type parameter
|
|
101
|
+
* const LowercaseQuery = CreateTransformingDecorator<string>(
|
|
102
|
+
* (req) => req.query.search as string,
|
|
103
|
+
* { transform: (v) => (v as string).toLowerCase() }
|
|
104
|
+
* );
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function CreateTransformingDecorator<T = any>(extractor: (request: Request, ctx: ExecutionContext) => T, options?: TransformingDecoratorOptions): ParameterDecorator;
|
|
108
|
+
//# sourceMappingURL=decorator-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator-factory.d.ts","sourceRoot":"","sources":["../../../src/common/decorators/decorator-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,gBAAgB,EAAe,MAAM,gBAAgB,CAAC;AACrF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC;;GAEG;AAEH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAExC;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CACvC;AAED;;GAEG;AACH,MAAM,WAAW,2BAA4B,SAAQ,oBAAoB;IACxE;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC;CACX;AAED;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,oBAAoB;IACvE;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,oBAAoB;IACzE;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAEpE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,GAAG,GAAG,EACrD,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,gBAAgB,KAAK,CAAC,EACzD,OAAO,GAAE,oBAAyB,GAChC,kBAAkB,CAmBpB;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,2BAA2B,GAAG,eAAe,CAEhG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,GAAG,GAAG,EAChD,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,gBAAgB,KAAK,CAAC,EACzD,OAAO,GAAE,0BAA+B,GACtC,kBAAkB,CAsBpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,GAAG,GAAG,EAClD,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,gBAAgB,KAAK,CAAC,EACzD,OAAO,GAAE,4BAAiC,GACxC,kBAAkB,CAcpB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createParamDecorator, SetMetadata } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Gets the request object from HTTP execution context
|
|
4
|
+
* @param ctx - The execution context
|
|
5
|
+
* @returns The request object
|
|
6
|
+
*/
|
|
7
|
+
export function GetRequestFromContext(ctx) {
|
|
8
|
+
return ctx.switchToHttp().getRequest();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Base factory for creating parameter decorators that extend RequestProperty functionality
|
|
12
|
+
* @param extractor - Function that extracts the value from request
|
|
13
|
+
* @param options - Configuration options
|
|
14
|
+
* @returns Parameter decorator function
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // With explicit type parameter
|
|
18
|
+
* const MyDecorator = CreateRequestPropertyDecorator<string>(
|
|
19
|
+
* (req) => req.headers['x-custom-id'],
|
|
20
|
+
* { transform: (v) => (v as string).toUpperCase() }
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function CreateRequestPropertyDecorator(extractor, options = {}) {
|
|
25
|
+
return createParamDecorator((_data, ctx) => {
|
|
26
|
+
const request = GetRequestFromContext(ctx);
|
|
27
|
+
let value = extractor(request, ctx);
|
|
28
|
+
// Apply validation if provided
|
|
29
|
+
if (options.validate && !options.validate(value)) {
|
|
30
|
+
throw new Error('Validation failed for extracted value');
|
|
31
|
+
}
|
|
32
|
+
// Apply transformation if provided
|
|
33
|
+
if (options.transform) {
|
|
34
|
+
value = options.transform(value);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
})();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Factory for creating conditional decorators that set metadata
|
|
41
|
+
* @param options - Configuration options
|
|
42
|
+
* @returns Method decorator function
|
|
43
|
+
*/
|
|
44
|
+
export function CreateConditionalDecorator(options) {
|
|
45
|
+
return SetMetadata(options.key, options.value);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Factory for creating validating decorators
|
|
49
|
+
* @param extractor - Function that extracts the value from request
|
|
50
|
+
* @param options - Configuration options
|
|
51
|
+
* @returns Parameter decorator function
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // With explicit type parameter
|
|
55
|
+
* const ValidatedId = CreateValidatingDecorator<string>(
|
|
56
|
+
* (req) => req.params.id,
|
|
57
|
+
* { validate: (v) => typeof v === 'string' && v.length > 0 }
|
|
58
|
+
* );
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function CreateValidatingDecorator(extractor, options = {}) {
|
|
62
|
+
return createParamDecorator((_data, ctx) => {
|
|
63
|
+
const request = GetRequestFromContext(ctx);
|
|
64
|
+
let value = extractor(request, ctx);
|
|
65
|
+
// Apply validation if provided
|
|
66
|
+
if (options.validate) {
|
|
67
|
+
const isValid = options.validate(value);
|
|
68
|
+
if (!isValid && options.throwOnInvalid) {
|
|
69
|
+
throw new Error(options.errorMessage ?? 'Validation failed for extracted value');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Apply transformation if provided
|
|
73
|
+
if (options.transform) {
|
|
74
|
+
value = options.transform(value);
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
})();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Factory for creating transforming decorators
|
|
81
|
+
* @param extractor - Function that extracts the value from request
|
|
82
|
+
* @param options - Configuration options
|
|
83
|
+
* @returns Parameter decorator function
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* // With explicit type parameter
|
|
87
|
+
* const LowercaseQuery = CreateTransformingDecorator<string>(
|
|
88
|
+
* (req) => req.query.search as string,
|
|
89
|
+
* { transform: (v) => (v as string).toLowerCase() }
|
|
90
|
+
* );
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export function CreateTransformingDecorator(extractor, options = {}) {
|
|
94
|
+
return createParamDecorator((_data, ctx) => {
|
|
95
|
+
const request = GetRequestFromContext(ctx);
|
|
96
|
+
let value = extractor(request, ctx);
|
|
97
|
+
// Apply transformation if provided
|
|
98
|
+
if (options.transform && (value !== undefined || options.transformUndefined)) {
|
|
99
|
+
value = options.transform(value);
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
})();
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=decorator-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator-factory.js","sourceRoot":"","sources":["../../../src/common/decorators/decorator-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAoB,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA2DrF;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAqB;IAC1D,OAAO,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAW,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,8BAA8B,CAC7C,SAAyD,EACzD,UAAgC,EAAE;IAElC,OAAO,oBAAoB,CAC1B,CAAC,KAAc,EAAE,GAAqB,EAAK,EAAE;QAC5C,MAAM,OAAO,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,KAAK,GAAY,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAE7C,+BAA+B;QAC/B,IAAI,OAAO,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC1D,CAAC;QAED,mCAAmC;QACnC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACvB,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,KAAU,CAAC;IACnB,CAAC,CACD,EAAE,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAAoC;IAC9E,OAAO,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,yBAAyB,CACxC,SAAyD,EACzD,UAAsC,EAAE;IAExC,OAAO,oBAAoB,CAC1B,CAAC,KAAc,EAAE,GAAqB,EAAK,EAAE;QAC5C,MAAM,OAAO,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,KAAK,GAAY,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAE7C,+BAA+B;QAC/B,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACtB,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACxC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;gBACxC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,IAAI,uCAAuC,CAAC,CAAC;YAClF,CAAC;QACF,CAAC;QAED,mCAAmC;QACnC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACvB,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,KAAU,CAAC;IACnB,CAAC,CACD,EAAE,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,2BAA2B,CAC1C,SAAyD,EACzD,UAAwC,EAAE;IAE1C,OAAO,oBAAoB,CAC1B,CAAC,KAAc,EAAE,GAAqB,EAAK,EAAE;QAC5C,MAAM,OAAO,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,KAAK,GAAY,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAE7C,mCAAmC;QACnC,IAAI,OAAO,CAAC,SAAS,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC9E,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,KAAU,CAAC;IACnB,CAAC,CACD,EAAE,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decorator to specify required roles for a route or method
|
|
3
|
+
*
|
|
4
|
+
* @param roles - Array of role names required to access the resource
|
|
5
|
+
* @returns Method decorator
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @Roles('admin', 'moderator')
|
|
10
|
+
* @Get('admin-only')
|
|
11
|
+
* async getAdminData() {
|
|
12
|
+
* // Only users with 'admin' or 'moderator' roles can access
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const Roles: (...roles: string[]) => MethodDecorator;
|
|
17
|
+
/**
|
|
18
|
+
* Decorator to specify required permissions for a route or method
|
|
19
|
+
*
|
|
20
|
+
* @param permissions - Array of permission names required to access the resource
|
|
21
|
+
* @returns Method decorator
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* @Permissions('user.create', 'user.update')
|
|
26
|
+
* @Post('users')
|
|
27
|
+
* async createUser(@Body() userData: CreateUserDto) {
|
|
28
|
+
* // Only users with 'user.create' AND 'user.update' permissions can access
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const Permissions: (...permissions: string[]) => MethodDecorator;
|
|
33
|
+
/**
|
|
34
|
+
* Decorator to mark a route as public (bypasses authentication guards)
|
|
35
|
+
*
|
|
36
|
+
* @returns Method decorator
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* @Public()
|
|
41
|
+
* @Get('health')
|
|
42
|
+
* async getHealth() {
|
|
43
|
+
* // This endpoint is accessible without authentication
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare const Public: () => MethodDecorator;
|
|
48
|
+
//# sourceMappingURL=guard.decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.decorators.d.ts","sourceRoot":"","sources":["../../../src/common/decorators/guard.decorators.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,KAAK,GAAI,GAAG,OAAO,MAAM,EAAE,KAAG,eAA8C,CAAC;AAE1F;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,GAAI,GAAG,aAAa,MAAM,EAAE,KAAG,eAA0D,CAAC;AAElH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM,QAAO,eAAgD,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SetMetadata } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Decorator to specify required roles for a route or method
|
|
4
|
+
*
|
|
5
|
+
* @param roles - Array of role names required to access the resource
|
|
6
|
+
* @returns Method decorator
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Roles('admin', 'moderator')
|
|
11
|
+
* @Get('admin-only')
|
|
12
|
+
* async getAdminData() {
|
|
13
|
+
* // Only users with 'admin' or 'moderator' roles can access
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const Roles = (...roles) => SetMetadata('roles', roles);
|
|
18
|
+
/**
|
|
19
|
+
* Decorator to specify required permissions for a route or method
|
|
20
|
+
*
|
|
21
|
+
* @param permissions - Array of permission names required to access the resource
|
|
22
|
+
* @returns Method decorator
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* @Permissions('user.create', 'user.update')
|
|
27
|
+
* @Post('users')
|
|
28
|
+
* async createUser(@Body() userData: CreateUserDto) {
|
|
29
|
+
* // Only users with 'user.create' AND 'user.update' permissions can access
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const Permissions = (...permissions) => SetMetadata('permissions', permissions);
|
|
34
|
+
/**
|
|
35
|
+
* Decorator to mark a route as public (bypasses authentication guards)
|
|
36
|
+
*
|
|
37
|
+
* @returns Method decorator
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* @Public()
|
|
42
|
+
* @Get('health')
|
|
43
|
+
* async getHealth() {
|
|
44
|
+
* // This endpoint is accessible without authentication
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export const Public = () => SetMetadata('isPublic', true);
|
|
49
|
+
//# sourceMappingURL=guard.decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.decorators.js","sourceRoot":"","sources":["../../../src/common/decorators/guard.decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAG,KAAe,EAAmB,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAE1F;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAG,WAAqB,EAAmB,EAAE,CAAC,WAAW,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAElH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,GAAoB,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { RequestProperty } from './request-property.decorator.js';
|
|
2
|
+
export type { RequestPropertyOptions } from './request-property.decorator.js';
|
|
3
|
+
export { CreateRequestPropertyDecorator as createRequestPropertyDecorator, CreateConditionalDecorator as createConditionalDecorator, CreateValidatingDecorator as createValidatingDecorator, CreateTransformingDecorator as createTransformingDecorator, GetRequestFromContext as getRequestFromContext, } from './decorator-factory.js';
|
|
4
|
+
export { ObjectGetPropertyByPath as GetNestedProperty, ObjectGetPropertyByPath as getNestedProperty } from '@pawells/typescript-common';
|
|
5
|
+
export type { BaseDecoratorOptions, ConditionalDecoratorOptions, ValidatingDecoratorOptions, TransformingDecoratorOptions, } from './decorator-factory.js';
|
|
6
|
+
export { Query, Params, Body, Headers, Cookies, } from './common-decorators.js';
|
|
7
|
+
export * from './guard.decorators.js';
|
|
8
|
+
export { InstrumentationRegistryHolder, Instrument } from './instrument.decorator.js';
|
|
9
|
+
export type { InstrumentOptions } from './instrument.decorator.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAG9E,OAAO,EACN,8BAA8B,IAAI,8BAA8B,EAChE,0BAA0B,IAAI,0BAA0B,EACxD,yBAAyB,IAAI,yBAAyB,EACtD,2BAA2B,IAAI,2BAA2B,EAC1D,qBAAqB,IAAI,qBAAqB,GAC9C,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,uBAAuB,IAAI,iBAAiB,EAAE,uBAAuB,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACxI,YAAY,EACX,oBAAoB,EACpB,2BAA2B,EAC3B,0BAA0B,EAC1B,4BAA4B,GAC5B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACN,KAAK,EACL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,OAAO,GACP,MAAM,wBAAwB,CAAC;AAGhC,cAAc,uBAAuB,CAAC;AAGtC,OAAO,EAAE,6BAA6B,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACtF,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { RequestProperty } from './request-property.decorator.js';
|
|
2
|
+
// Decorator factories
|
|
3
|
+
export { CreateRequestPropertyDecorator as createRequestPropertyDecorator, CreateConditionalDecorator as createConditionalDecorator, CreateValidatingDecorator as createValidatingDecorator, CreateTransformingDecorator as createTransformingDecorator, GetRequestFromContext as getRequestFromContext, } from './decorator-factory.js';
|
|
4
|
+
export { ObjectGetPropertyByPath as GetNestedProperty, ObjectGetPropertyByPath as getNestedProperty } from '@pawells/typescript-common';
|
|
5
|
+
// Common decorators
|
|
6
|
+
export { Query, Params, Body, Headers, Cookies, } from './common-decorators.js';
|
|
7
|
+
// Guard decorators
|
|
8
|
+
export * from './guard.decorators.js';
|
|
9
|
+
// Instrumentation
|
|
10
|
+
export { InstrumentationRegistryHolder, Instrument } from './instrument.decorator.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGlE,sBAAsB;AACtB,OAAO,EACN,8BAA8B,IAAI,8BAA8B,EAChE,0BAA0B,IAAI,0BAA0B,EACxD,yBAAyB,IAAI,yBAAyB,EACtD,2BAA2B,IAAI,2BAA2B,EAC1D,qBAAqB,IAAI,qBAAqB,GAC9C,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,uBAAuB,IAAI,iBAAiB,EAAE,uBAAuB,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAQxI,oBAAoB;AACpB,OAAO,EACN,KAAK,EACL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,OAAO,GACP,MAAM,wBAAwB,CAAC;AAEhC,mBAAmB;AACnB,cAAc,uBAAuB,CAAC;AAEtC,kBAAkB;AAClB,OAAO,EAAE,6BAA6B,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { InstrumentationRegistry } from '../registry/instrumentation-registry.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the @Instrument() method decorator
|
|
4
|
+
*
|
|
5
|
+
* Configures automatic timing, counter, and error tracking for decorated methods.
|
|
6
|
+
* Metrics are automatically registered on first invocation.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Instrument({
|
|
11
|
+
* timing: 'user_service_find_by_id_seconds',
|
|
12
|
+
* counters: ['user_service_find_by_id_success'],
|
|
13
|
+
* errorCounters: ['user_service_find_by_id_error'],
|
|
14
|
+
* labels: (userId: string) => ({ userId }),
|
|
15
|
+
* })
|
|
16
|
+
* async findById(userId: string): Promise<User> {
|
|
17
|
+
* // Implementation
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export interface InstrumentOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Name of the histogram metric to record method timing (in seconds).
|
|
24
|
+
* If provided, timing will be recorded for all invocations.
|
|
25
|
+
*
|
|
26
|
+
* @optional
|
|
27
|
+
*/
|
|
28
|
+
timing?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Counter metric names to increment on successful completion.
|
|
31
|
+
* Incremented after the method returns (or resolves for async).
|
|
32
|
+
*
|
|
33
|
+
* @optional
|
|
34
|
+
*/
|
|
35
|
+
counters?: string[];
|
|
36
|
+
/**
|
|
37
|
+
* Counter metric names to increment on exception.
|
|
38
|
+
* Incremented if the method throws or rejects.
|
|
39
|
+
*
|
|
40
|
+
* @optional
|
|
41
|
+
*/
|
|
42
|
+
errorCounters?: string[];
|
|
43
|
+
/**
|
|
44
|
+
* Static labels to attach to all recorded metrics, or a function that extracts labels
|
|
45
|
+
* from method arguments.
|
|
46
|
+
*
|
|
47
|
+
* If a function, it receives the argument array and returns a Record of label values.
|
|
48
|
+
* Static labels (object) are always used. Function labels are computed per invocation.
|
|
49
|
+
*
|
|
50
|
+
* @optional
|
|
51
|
+
*/
|
|
52
|
+
labels?: Record<string, string | number> | ((...args: unknown[]) => Record<string, string | number>);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Module-level singleton holder for InstrumentationRegistry.
|
|
56
|
+
*
|
|
57
|
+
* The @Instrument() decorator uses this holder to access the registry
|
|
58
|
+
* without requiring direct DI into every decorated method.
|
|
59
|
+
*
|
|
60
|
+
* Set during application bootstrap by CommonModule.onModuleInit().
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // In CommonModule.onModuleInit()
|
|
65
|
+
* InstrumentationRegistryHolder.setInstance(this.registry);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare class InstrumentationRegistryHolder {
|
|
69
|
+
/**
|
|
70
|
+
* Singleton instance of InstrumentationRegistry
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
private static instance;
|
|
74
|
+
/**
|
|
75
|
+
* Set the singleton instance.
|
|
76
|
+
* Called during application bootstrap.
|
|
77
|
+
*
|
|
78
|
+
* @param registry - The InstrumentationRegistry instance
|
|
79
|
+
*/
|
|
80
|
+
static setInstance(registry: InstrumentationRegistry): void;
|
|
81
|
+
/**
|
|
82
|
+
* Get the singleton instance.
|
|
83
|
+
*
|
|
84
|
+
* @returns The InstrumentationRegistry instance, or null if not yet set
|
|
85
|
+
*/
|
|
86
|
+
static getInstance(): InstrumentationRegistry | null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Method decorator for automatic metrics instrumentation.
|
|
90
|
+
*
|
|
91
|
+
* Automatically records method timing (histogram), success counters, and error counters
|
|
92
|
+
* using the InstrumentationRegistry. Metric descriptors are auto-registered on first use.
|
|
93
|
+
*
|
|
94
|
+
* Supports both synchronous and asynchronous (Promise-returning) methods.
|
|
95
|
+
*
|
|
96
|
+
* @param options - Instrumentation configuration (timing, counters, errorCounters, labels)
|
|
97
|
+
* @returns MethodDecorator
|
|
98
|
+
*
|
|
99
|
+
* @throws Error if a metric name is not registered (only if registry is available)
|
|
100
|
+
* @throws The original error if the decorated method throws/rejects
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* class UserService {
|
|
105
|
+
* @Instrument({
|
|
106
|
+
* timing: 'user_service_create_duration_seconds',
|
|
107
|
+
* counters: ['user_service_create_total'],
|
|
108
|
+
* errorCounters: ['user_service_create_errors'],
|
|
109
|
+
* labels: { service: 'user' },
|
|
110
|
+
* })
|
|
111
|
+
* async create(userData: CreateUserDto): Promise<User> {
|
|
112
|
+
* return this.repository.save(userData);
|
|
113
|
+
* }
|
|
114
|
+
*
|
|
115
|
+
* @Instrument({
|
|
116
|
+
* timing: 'user_service_find_by_id_duration_seconds',
|
|
117
|
+
* counters: ['user_service_find_by_id_total'],
|
|
118
|
+
* errorCounters: ['user_service_find_by_id_errors'],
|
|
119
|
+
* labels: (id: string) => ({ userId: id }),
|
|
120
|
+
* })
|
|
121
|
+
* async findById(id: string): Promise<User | null> {
|
|
122
|
+
* return this.repository.findOne(id);
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function Instrument(options: InstrumentOptions): MethodDecorator;
|
|
128
|
+
//# sourceMappingURL=instrument.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrument.decorator.d.ts","sourceRoot":"","sources":["../../../src/common/decorators/instrument.decorator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAEvF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,iBAAiB;IACjC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAEzB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;CACrG;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,6BAA6B;IACzC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAwC;IAE/D;;;;;OAKG;WACW,WAAW,CAAC,QAAQ,EAAE,uBAAuB,GAAG,IAAI;IAIlE;;;;OAIG;WACW,WAAW,IAAI,uBAAuB,GAAG,IAAI;CAG3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,eAAe,CAwGtE"}
|