@riktajs/core 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/index.cjs +3591 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +770 -0
  4. package/dist/index.d.ts +770 -2
  5. package/dist/index.js +3415 -2
  6. package/dist/index.js.map +1 -0
  7. package/package.json +63 -56
  8. package/dist/core/application.d.ts +0 -6
  9. package/dist/core/application.js +0 -248
  10. package/dist/core/config/abstract-config-provider.d.ts +0 -14
  11. package/dist/core/config/abstract-config-provider.js +0 -53
  12. package/dist/core/config/env-loader.d.ts +0 -3
  13. package/dist/core/config/env-loader.js +0 -26
  14. package/dist/core/config/index.d.ts +0 -2
  15. package/dist/core/config/index.js +0 -2
  16. package/dist/core/constants.d.ts +0 -30
  17. package/dist/core/constants.js +0 -31
  18. package/dist/core/container/abstract-class.utils.d.ts +0 -10
  19. package/dist/core/container/abstract-class.utils.js +0 -44
  20. package/dist/core/container/container.d.ts +0 -32
  21. package/dist/core/container/container.js +0 -292
  22. package/dist/core/container/implements.decorator.d.ts +0 -6
  23. package/dist/core/container/implements.decorator.js +0 -39
  24. package/dist/core/container/index.d.ts +0 -5
  25. package/dist/core/container/index.js +0 -5
  26. package/dist/core/container/injection-token.d.ts +0 -29
  27. package/dist/core/container/injection-token.js +0 -11
  28. package/dist/core/container/request-scope.d.ts +0 -16
  29. package/dist/core/container/request-scope.js +0 -49
  30. package/dist/core/decorators/apply-decorators.d.ts +0 -8
  31. package/dist/core/decorators/apply-decorators.js +0 -36
  32. package/dist/core/decorators/autowired.decorator.d.ts +0 -11
  33. package/dist/core/decorators/autowired.decorator.js +0 -78
  34. package/dist/core/decorators/config-property.decorator.d.ts +0 -9
  35. package/dist/core/decorators/config-property.decorator.js +0 -59
  36. package/dist/core/decorators/controller.decorator.d.ts +0 -5
  37. package/dist/core/decorators/controller.decorator.js +0 -18
  38. package/dist/core/decorators/create-param-decorator.d.ts +0 -11
  39. package/dist/core/decorators/create-param-decorator.js +0 -21
  40. package/dist/core/decorators/index.d.ts +0 -9
  41. package/dist/core/decorators/index.js +0 -9
  42. package/dist/core/decorators/injectable.decorator.d.ts +0 -3
  43. package/dist/core/decorators/injectable.decorator.js +0 -11
  44. package/dist/core/decorators/param.decorator.d.ts +0 -59
  45. package/dist/core/decorators/param.decorator.js +0 -38
  46. package/dist/core/decorators/provider.decorator.d.ts +0 -12
  47. package/dist/core/decorators/provider.decorator.js +0 -56
  48. package/dist/core/decorators/route.decorator.d.ts +0 -9
  49. package/dist/core/decorators/route.decorator.js +0 -30
  50. package/dist/core/discovery.d.ts +0 -3
  51. package/dist/core/discovery.js +0 -111
  52. package/dist/core/exceptions/catch.decorator.d.ts +0 -8
  53. package/dist/core/exceptions/catch.decorator.js +0 -13
  54. package/dist/core/exceptions/config.exceptions.d.ts +0 -9
  55. package/dist/core/exceptions/config.exceptions.js +0 -34
  56. package/dist/core/exceptions/discovery.exception.d.ts +0 -18
  57. package/dist/core/exceptions/discovery.exception.js +0 -39
  58. package/dist/core/exceptions/exception-filter.d.ts +0 -38
  59. package/dist/core/exceptions/exception-filter.js +0 -103
  60. package/dist/core/exceptions/exceptions.d.ts +0 -55
  61. package/dist/core/exceptions/exceptions.js +0 -91
  62. package/dist/core/exceptions/http-exception.d.ts +0 -24
  63. package/dist/core/exceptions/http-exception.js +0 -62
  64. package/dist/core/exceptions/index.d.ts +0 -7
  65. package/dist/core/exceptions/index.js +0 -7
  66. package/dist/core/exceptions/validation.exception.d.ts +0 -17
  67. package/dist/core/exceptions/validation.exception.js +0 -33
  68. package/dist/core/guards/can-activate.interface.d.ts +0 -4
  69. package/dist/core/guards/can-activate.interface.js +0 -1
  70. package/dist/core/guards/execution-context.d.ts +0 -28
  71. package/dist/core/guards/execution-context.js +0 -35
  72. package/dist/core/guards/index.d.ts +0 -3
  73. package/dist/core/guards/index.js +0 -2
  74. package/dist/core/guards/use-guards.decorator.d.ts +0 -6
  75. package/dist/core/guards/use-guards.decorator.js +0 -22
  76. package/dist/core/index.d.ts +0 -19
  77. package/dist/core/index.js +0 -17
  78. package/dist/core/interceptors/index.d.ts +0 -2
  79. package/dist/core/interceptors/index.js +0 -1
  80. package/dist/core/interceptors/interceptor.interface.d.ts +0 -7
  81. package/dist/core/interceptors/interceptor.interface.js +0 -1
  82. package/dist/core/interceptors/use-interceptors.decorator.d.ts +0 -6
  83. package/dist/core/interceptors/use-interceptors.decorator.js +0 -19
  84. package/dist/core/lifecycle/event-bus.d.ts +0 -57
  85. package/dist/core/lifecycle/event-bus.js +0 -108
  86. package/dist/core/lifecycle/index.d.ts +0 -3
  87. package/dist/core/lifecycle/index.js +0 -3
  88. package/dist/core/lifecycle/interfaces.d.ts +0 -15
  89. package/dist/core/lifecycle/interfaces.js +0 -1
  90. package/dist/core/lifecycle/on.decorator.d.ts +0 -11
  91. package/dist/core/lifecycle/on.decorator.js +0 -13
  92. package/dist/core/metadata.d.ts +0 -20
  93. package/dist/core/metadata.js +0 -64
  94. package/dist/core/middleware/index.d.ts +0 -3
  95. package/dist/core/middleware/index.js +0 -2
  96. package/dist/core/middleware/middleware.decorator.d.ts +0 -2
  97. package/dist/core/middleware/middleware.decorator.js +0 -7
  98. package/dist/core/middleware/rikta-middleware.interface.d.ts +0 -5
  99. package/dist/core/middleware/rikta-middleware.interface.js +0 -1
  100. package/dist/core/middleware/use-middleware.decorator.d.ts +0 -6
  101. package/dist/core/middleware/use-middleware.decorator.js +0 -22
  102. package/dist/core/profiler/index.d.ts +0 -2
  103. package/dist/core/profiler/index.js +0 -1
  104. package/dist/core/profiler/performance-profiler.d.ts +0 -42
  105. package/dist/core/profiler/performance-profiler.js +0 -95
  106. package/dist/core/registry.d.ts +0 -41
  107. package/dist/core/registry.js +0 -109
  108. package/dist/core/router/router.d.ts +0 -32
  109. package/dist/core/router/router.js +0 -300
  110. package/dist/core/types.d.ts +0 -62
  111. package/dist/core/types.js +0 -1
@@ -1,103 +0,0 @@
1
- import { HttpException } from './http-exception.js';
2
- export class GlobalExceptionFilter {
3
- includeStack;
4
- logErrors;
5
- constructor(options = {}) {
6
- this.includeStack = options.includeStack ?? process.env.NODE_ENV !== 'production';
7
- this.logErrors = options.logErrors ?? true;
8
- }
9
- catch(exception, context) {
10
- const { request, reply, path, method } = context;
11
- const requestId = request.id ?? undefined;
12
- if (this.logErrors) {
13
- this.logError(exception, method, path, requestId);
14
- }
15
- const response = this.buildResponse(exception, path, requestId);
16
- reply.status(response.statusCode).send(response);
17
- }
18
- buildResponse(exception, path, requestId) {
19
- if (exception instanceof HttpException) {
20
- const httpResponse = exception.getResponse();
21
- return {
22
- statusCode: httpResponse.statusCode,
23
- message: httpResponse.message,
24
- error: httpResponse.error,
25
- timestamp: httpResponse.timestamp,
26
- path,
27
- ...(requestId ? { requestId } : {}),
28
- ...(httpResponse.details ? { details: httpResponse.details } : {}),
29
- ...(httpResponse.code ? { code: httpResponse.code } : {}),
30
- ...(this.includeStack ? { stack: exception.stack } : {}),
31
- };
32
- }
33
- if (this.isFastifyValidationError(exception)) {
34
- return {
35
- statusCode: 400,
36
- message: 'Validation failed',
37
- error: 'Bad Request',
38
- timestamp: new Date().toISOString(),
39
- path,
40
- ...(requestId && { requestId }),
41
- details: exception.validation,
42
- ...(this.includeStack && { stack: exception.stack }),
43
- };
44
- }
45
- if (this.isFastifyError(exception)) {
46
- const fastifyError = exception;
47
- return {
48
- statusCode: fastifyError.statusCode ?? 500,
49
- message: fastifyError.message,
50
- error: fastifyError.code ?? 'Error',
51
- timestamp: new Date().toISOString(),
52
- path,
53
- ...(requestId && { requestId }),
54
- ...(this.includeStack && { stack: exception.stack }),
55
- };
56
- }
57
- return {
58
- statusCode: 500,
59
- message: this.includeStack ? exception.message : 'Internal Server Error',
60
- error: 'Internal Server Error',
61
- timestamp: new Date().toISOString(),
62
- path,
63
- ...(requestId && { requestId }),
64
- ...(this.includeStack && { stack: exception.stack }),
65
- };
66
- }
67
- isFastifyValidationError(error) {
68
- return 'validation' in error && Array.isArray(error.validation);
69
- }
70
- isFastifyError(error) {
71
- return 'statusCode' in error;
72
- }
73
- logError(exception, method, path, requestId) {
74
- const timestamp = new Date().toISOString();
75
- const status = exception instanceof HttpException
76
- ? exception.getStatus()
77
- : 500;
78
- const prefix = status >= 500 ? '❌' : '⚠️';
79
- const reqIdStr = requestId ? ` [${requestId}]` : '';
80
- console.error(`${prefix} [${timestamp}]${reqIdStr} ${method} ${path} - ${status} ${exception.message}`);
81
- if (status >= 500 && this.includeStack && exception.stack) {
82
- console.error(exception.stack);
83
- }
84
- }
85
- }
86
- export function createExceptionHandler(filter, customFilters = new Map()) {
87
- return async (error, request, reply) => {
88
- const context = {
89
- exception: error,
90
- request,
91
- reply,
92
- path: request.url,
93
- method: request.method,
94
- requestId: request.id,
95
- };
96
- for (const [ExceptionType, customFilter] of customFilters) {
97
- if (error instanceof ExceptionType) {
98
- return customFilter.catch(error, context);
99
- }
100
- }
101
- return filter.catch(error, context);
102
- };
103
- }
@@ -1,55 +0,0 @@
1
- import { HttpException, HttpExceptionBody } from './http-exception.js';
2
- export declare class BadRequestException extends HttpException {
3
- constructor(response?: string | HttpExceptionBody);
4
- }
5
- export declare class UnauthorizedException extends HttpException {
6
- constructor(response?: string | HttpExceptionBody);
7
- }
8
- export declare class ForbiddenException extends HttpException {
9
- constructor(response?: string | HttpExceptionBody);
10
- }
11
- export declare class NotFoundException extends HttpException {
12
- constructor(response?: string | HttpExceptionBody);
13
- }
14
- export declare class MethodNotAllowedException extends HttpException {
15
- constructor(response?: string | HttpExceptionBody);
16
- }
17
- export declare class NotAcceptableException extends HttpException {
18
- constructor(response?: string | HttpExceptionBody);
19
- }
20
- export declare class RequestTimeoutException extends HttpException {
21
- constructor(response?: string | HttpExceptionBody);
22
- }
23
- export declare class ConflictException extends HttpException {
24
- constructor(response?: string | HttpExceptionBody);
25
- }
26
- export declare class GoneException extends HttpException {
27
- constructor(response?: string | HttpExceptionBody);
28
- }
29
- export declare class PayloadTooLargeException extends HttpException {
30
- constructor(response?: string | HttpExceptionBody);
31
- }
32
- export declare class UnsupportedMediaTypeException extends HttpException {
33
- constructor(response?: string | HttpExceptionBody);
34
- }
35
- export declare class UnprocessableEntityException extends HttpException {
36
- constructor(response?: string | HttpExceptionBody);
37
- }
38
- export declare class TooManyRequestsException extends HttpException {
39
- constructor(response?: string | HttpExceptionBody);
40
- }
41
- export declare class InternalServerErrorException extends HttpException {
42
- constructor(response?: string | HttpExceptionBody);
43
- }
44
- export declare class NotImplementedException extends HttpException {
45
- constructor(response?: string | HttpExceptionBody);
46
- }
47
- export declare class BadGatewayException extends HttpException {
48
- constructor(response?: string | HttpExceptionBody);
49
- }
50
- export declare class ServiceUnavailableException extends HttpException {
51
- constructor(response?: string | HttpExceptionBody);
52
- }
53
- export declare class GatewayTimeoutException extends HttpException {
54
- constructor(response?: string | HttpExceptionBody);
55
- }
@@ -1,91 +0,0 @@
1
- import { HttpException } from './http-exception.js';
2
- export class BadRequestException extends HttpException {
3
- constructor(response = 'Bad Request') {
4
- super(response, 400);
5
- }
6
- }
7
- export class UnauthorizedException extends HttpException {
8
- constructor(response = 'Unauthorized') {
9
- super(response, 401);
10
- }
11
- }
12
- export class ForbiddenException extends HttpException {
13
- constructor(response = 'Forbidden') {
14
- super(response, 403);
15
- }
16
- }
17
- export class NotFoundException extends HttpException {
18
- constructor(response = 'Not Found') {
19
- super(response, 404);
20
- }
21
- }
22
- export class MethodNotAllowedException extends HttpException {
23
- constructor(response = 'Method Not Allowed') {
24
- super(response, 405);
25
- }
26
- }
27
- export class NotAcceptableException extends HttpException {
28
- constructor(response = 'Not Acceptable') {
29
- super(response, 406);
30
- }
31
- }
32
- export class RequestTimeoutException extends HttpException {
33
- constructor(response = 'Request Timeout') {
34
- super(response, 408);
35
- }
36
- }
37
- export class ConflictException extends HttpException {
38
- constructor(response = 'Conflict') {
39
- super(response, 409);
40
- }
41
- }
42
- export class GoneException extends HttpException {
43
- constructor(response = 'Gone') {
44
- super(response, 410);
45
- }
46
- }
47
- export class PayloadTooLargeException extends HttpException {
48
- constructor(response = 'Payload Too Large') {
49
- super(response, 413);
50
- }
51
- }
52
- export class UnsupportedMediaTypeException extends HttpException {
53
- constructor(response = 'Unsupported Media Type') {
54
- super(response, 415);
55
- }
56
- }
57
- export class UnprocessableEntityException extends HttpException {
58
- constructor(response = 'Unprocessable Entity') {
59
- super(response, 422);
60
- }
61
- }
62
- export class TooManyRequestsException extends HttpException {
63
- constructor(response = 'Too Many Requests') {
64
- super(response, 429);
65
- }
66
- }
67
- export class InternalServerErrorException extends HttpException {
68
- constructor(response = 'Internal Server Error') {
69
- super(response, 500);
70
- }
71
- }
72
- export class NotImplementedException extends HttpException {
73
- constructor(response = 'Not Implemented') {
74
- super(response, 501);
75
- }
76
- }
77
- export class BadGatewayException extends HttpException {
78
- constructor(response = 'Bad Gateway') {
79
- super(response, 502);
80
- }
81
- }
82
- export class ServiceUnavailableException extends HttpException {
83
- constructor(response = 'Service Unavailable') {
84
- super(response, 503);
85
- }
86
- }
87
- export class GatewayTimeoutException extends HttpException {
88
- constructor(response = 'Gateway Timeout') {
89
- super(response, 504);
90
- }
91
- }
@@ -1,24 +0,0 @@
1
- export declare class HttpException extends Error {
2
- readonly statusCode: number;
3
- readonly response: HttpExceptionResponse;
4
- readonly timestamp: string;
5
- constructor(response: string | HttpExceptionBody, statusCode?: number);
6
- getResponse(): HttpExceptionResponse;
7
- getStatus(): number;
8
- private getDefaultError;
9
- }
10
- export interface HttpExceptionBody {
11
- message: string;
12
- error?: string;
13
- details?: unknown;
14
- code?: string;
15
- }
16
- export interface HttpExceptionResponse {
17
- statusCode: number;
18
- message: string;
19
- error: string;
20
- timestamp: string;
21
- details?: unknown;
22
- code?: string;
23
- path?: string;
24
- }
@@ -1,62 +0,0 @@
1
- export class HttpException extends Error {
2
- statusCode;
3
- response;
4
- timestamp;
5
- constructor(response, statusCode = 500) {
6
- const message = typeof response === 'string'
7
- ? response
8
- : response.message;
9
- super(message);
10
- this.name = this.constructor.name;
11
- this.statusCode = statusCode;
12
- this.timestamp = new Date().toISOString();
13
- if (typeof response === 'string') {
14
- this.response = {
15
- statusCode,
16
- message,
17
- error: this.getDefaultError(statusCode),
18
- timestamp: this.timestamp,
19
- };
20
- }
21
- else {
22
- this.response = {
23
- statusCode,
24
- message: response.message,
25
- error: response.error ?? this.getDefaultError(statusCode),
26
- timestamp: this.timestamp,
27
- ...(response.details ? { details: response.details } : {}),
28
- ...(response.code ? { code: response.code } : {}),
29
- };
30
- }
31
- Error.captureStackTrace(this, this.constructor);
32
- }
33
- getResponse() {
34
- return this.response;
35
- }
36
- getStatus() {
37
- return this.statusCode;
38
- }
39
- getDefaultError(statusCode) {
40
- const errors = {
41
- 400: 'Bad Request',
42
- 401: 'Unauthorized',
43
- 403: 'Forbidden',
44
- 404: 'Not Found',
45
- 405: 'Method Not Allowed',
46
- 406: 'Not Acceptable',
47
- 408: 'Request Timeout',
48
- 409: 'Conflict',
49
- 410: 'Gone',
50
- 413: 'Payload Too Large',
51
- 415: 'Unsupported Media Type',
52
- 422: 'Unprocessable Entity',
53
- 429: 'Too Many Requests',
54
- 500: 'Internal Server Error',
55
- 501: 'Not Implemented',
56
- 502: 'Bad Gateway',
57
- 503: 'Service Unavailable',
58
- 504: 'Gateway Timeout',
59
- };
60
- return errors[statusCode] ?? 'Error';
61
- }
62
- }
@@ -1,7 +0,0 @@
1
- export { HttpException, HttpExceptionBody, HttpExceptionResponse } from './http-exception.js';
2
- export { ValidationException, ValidationErrorDetails } from './validation.exception.js';
3
- export { BadRequestException, UnauthorizedException, ForbiddenException, NotFoundException, MethodNotAllowedException, NotAcceptableException, RequestTimeoutException, ConflictException, GoneException, PayloadTooLargeException, UnsupportedMediaTypeException, UnprocessableEntityException, TooManyRequestsException, InternalServerErrorException, NotImplementedException, BadGatewayException, ServiceUnavailableException, GatewayTimeoutException, } from './exceptions.js';
4
- export { ExceptionFilter, ExceptionContext, ErrorResponse, GlobalExceptionFilter, GlobalExceptionFilterOptions, createExceptionHandler, } from './exception-filter.js';
5
- export { Catch, CatchMetadata, CATCH_METADATA, getCatchMetadata } from './catch.decorator.js';
6
- export { ConfigProviderAlreadyRegisteredException, ConfigProviderNotFoundException, ConfigProviderInstantiationException, } from './config.exceptions.js';
7
- export { DiscoveryException, DiscoveryFailure, DiscoveryOptions, } from './discovery.exception.js';
@@ -1,7 +0,0 @@
1
- export { HttpException } from './http-exception.js';
2
- export { ValidationException } from './validation.exception.js';
3
- export { BadRequestException, UnauthorizedException, ForbiddenException, NotFoundException, MethodNotAllowedException, NotAcceptableException, RequestTimeoutException, ConflictException, GoneException, PayloadTooLargeException, UnsupportedMediaTypeException, UnprocessableEntityException, TooManyRequestsException, InternalServerErrorException, NotImplementedException, BadGatewayException, ServiceUnavailableException, GatewayTimeoutException, } from './exceptions.js';
4
- export { GlobalExceptionFilter, createExceptionHandler, } from './exception-filter.js';
5
- export { Catch, CATCH_METADATA, getCatchMetadata } from './catch.decorator.js';
6
- export { ConfigProviderAlreadyRegisteredException, ConfigProviderNotFoundException, ConfigProviderInstantiationException, } from './config.exceptions.js';
7
- export { DiscoveryException, } from './discovery.exception.js';
@@ -1,17 +0,0 @@
1
- import type { ZodError } from 'zod';
2
- import { HttpException } from './http-exception.js';
3
- export interface ValidationErrorDetails {
4
- path: (string | number)[];
5
- message: string;
6
- code: string;
7
- expected?: string;
8
- received?: string;
9
- }
10
- export declare class ValidationException extends HttpException {
11
- readonly zodError: ZodError;
12
- readonly errors: ValidationErrorDetails[];
13
- constructor(zodError: ZodError, message?: string);
14
- getValidationErrors(): ValidationErrorDetails[];
15
- getFlattenedErrors(): import("zod").ZodFlattenedError<unknown, string>;
16
- getFormattedErrors(): import("zod").ZodFormattedError<unknown, string>;
17
- }
@@ -1,33 +0,0 @@
1
- import { HttpException } from './http-exception.js';
2
- export class ValidationException extends HttpException {
3
- zodError;
4
- errors;
5
- constructor(zodError, message = 'Validation failed') {
6
- const errors = zodError.issues.map((issue) => ({
7
- path: issue.path,
8
- message: issue.message,
9
- code: issue.code,
10
- ...(('expected' in issue) ? { expected: String(issue.expected) } : {}),
11
- ...(('received' in issue) ? { received: String(issue.received) } : {}),
12
- }));
13
- super({
14
- message,
15
- error: 'Validation Error',
16
- details: {
17
- errors,
18
- errorCount: errors.length,
19
- },
20
- }, 400);
21
- this.zodError = zodError;
22
- this.errors = errors;
23
- }
24
- getValidationErrors() {
25
- return this.errors;
26
- }
27
- getFlattenedErrors() {
28
- return this.zodError.flatten();
29
- }
30
- getFormattedErrors() {
31
- return this.zodError.format();
32
- }
33
- }
@@ -1,4 +0,0 @@
1
- import type { ExecutionContext } from './execution-context.js';
2
- export interface CanActivate {
3
- canActivate(context: ExecutionContext): boolean | Promise<boolean>;
4
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- import type { FastifyRequest, FastifyReply } from 'fastify';
2
- import type { Constructor } from '../types.js';
3
- export interface HttpArgumentsHost {
4
- getRequest<T = FastifyRequest>(): T;
5
- getResponse<T = FastifyReply>(): T;
6
- }
7
- export interface ExecutionContext {
8
- switchToHttp(): HttpArgumentsHost;
9
- getRequest<T = FastifyRequest>(): T;
10
- getReply<T = FastifyReply>(): T;
11
- getClass(): Constructor;
12
- getHandler(): string | symbol;
13
- getMetadata<T = unknown>(key: string | symbol): T | undefined;
14
- }
15
- export declare class ExecutionContextImpl implements ExecutionContext {
16
- private readonly request;
17
- private readonly reply;
18
- private readonly controllerClass;
19
- private readonly handlerName;
20
- private readonly httpHost;
21
- constructor(request: FastifyRequest, reply: FastifyReply, controllerClass: Constructor, handlerName: string | symbol);
22
- switchToHttp(): HttpArgumentsHost;
23
- getRequest<T = FastifyRequest>(): T;
24
- getReply<T = FastifyReply>(): T;
25
- getClass(): Constructor;
26
- getHandler(): string | symbol;
27
- getMetadata<T = unknown>(key: string | symbol): T | undefined;
28
- }
@@ -1,35 +0,0 @@
1
- export class ExecutionContextImpl {
2
- request;
3
- reply;
4
- controllerClass;
5
- handlerName;
6
- httpHost;
7
- constructor(request, reply, controllerClass, handlerName) {
8
- this.request = request;
9
- this.reply = reply;
10
- this.controllerClass = controllerClass;
11
- this.handlerName = handlerName;
12
- this.httpHost = {
13
- getRequest: () => this.request,
14
- getResponse: () => this.reply,
15
- };
16
- }
17
- switchToHttp() {
18
- return this.httpHost;
19
- }
20
- getRequest() {
21
- return this.request;
22
- }
23
- getReply() {
24
- return this.reply;
25
- }
26
- getClass() {
27
- return this.controllerClass;
28
- }
29
- getHandler() {
30
- return this.handlerName;
31
- }
32
- getMetadata(key) {
33
- return Reflect.getMetadata(key, this.controllerClass, this.handlerName);
34
- }
35
- }
@@ -1,3 +0,0 @@
1
- export { CanActivate } from './can-activate.interface.js';
2
- export { ExecutionContext, ExecutionContextImpl } from './execution-context.js';
3
- export { UseGuards, getGuardsMetadata } from './use-guards.decorator.js';
@@ -1,2 +0,0 @@
1
- export { ExecutionContextImpl } from './execution-context.js';
2
- export { UseGuards, getGuardsMetadata } from './use-guards.decorator.js';
@@ -1,6 +0,0 @@
1
- import 'reflect-metadata';
2
- import type { Constructor } from '../types.js';
3
- import type { CanActivate } from './can-activate.interface.js';
4
- export type GuardClass = Constructor<CanActivate>;
5
- export declare function UseGuards(...guards: GuardClass[]): ClassDecorator & MethodDecorator;
6
- export declare function getGuardsMetadata(target: Constructor, propertyKey?: string | symbol): GuardClass[];
@@ -1,22 +0,0 @@
1
- import 'reflect-metadata';
2
- import { GUARDS_METADATA } from '../constants.js';
3
- export function UseGuards(...guards) {
4
- return (target, propertyKey) => {
5
- if (propertyKey !== undefined) {
6
- const existingGuards = Reflect.getMetadata(GUARDS_METADATA, target.constructor, propertyKey) ?? [];
7
- Reflect.defineMetadata(GUARDS_METADATA, [...existingGuards, ...guards], target.constructor, propertyKey);
8
- }
9
- else {
10
- const existingGuards = Reflect.getMetadata(GUARDS_METADATA, target) ?? [];
11
- Reflect.defineMetadata(GUARDS_METADATA, [...existingGuards, ...guards], target);
12
- }
13
- };
14
- }
15
- export function getGuardsMetadata(target, propertyKey) {
16
- const classGuards = Reflect.getMetadata(GUARDS_METADATA, target) ?? [];
17
- if (!propertyKey) {
18
- return classGuards;
19
- }
20
- const methodGuards = Reflect.getMetadata(GUARDS_METADATA, target, propertyKey) ?? [];
21
- return [...classGuards, ...methodGuards];
22
- }
@@ -1,19 +0,0 @@
1
- export * from './types.js';
2
- export * from './constants.js';
3
- export * from './container/index.js';
4
- export * from './registry.js';
5
- export * from './discovery.js';
6
- export * from './lifecycle/index.js';
7
- export * from './router/router.js';
8
- export * from './application.js';
9
- export * from './decorators/index.js';
10
- export * from './exceptions/index.js';
11
- export * from './guards/index.js';
12
- export * from './middleware/index.js';
13
- export * from './interceptors/index.js';
14
- export * from './config/index.js';
15
- export * from './metadata.js';
16
- export * from './profiler/index.js';
17
- export { z } from 'zod';
18
- export type { ZodError, ZodIssue, infer as ZodInfer, input as ZodInput, output as ZodOutput } from 'zod';
19
- export type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
@@ -1,17 +0,0 @@
1
- export * from './types.js';
2
- export * from './constants.js';
3
- export * from './container/index.js';
4
- export * from './registry.js';
5
- export * from './discovery.js';
6
- export * from './lifecycle/index.js';
7
- export * from './router/router.js';
8
- export * from './application.js';
9
- export * from './decorators/index.js';
10
- export * from './exceptions/index.js';
11
- export * from './guards/index.js';
12
- export * from './middleware/index.js';
13
- export * from './interceptors/index.js';
14
- export * from './config/index.js';
15
- export * from './metadata.js';
16
- export * from './profiler/index.js';
17
- export { z } from 'zod';
@@ -1,2 +0,0 @@
1
- export { Interceptor, CallHandler } from './interceptor.interface.js';
2
- export { UseInterceptors, getInterceptorsMetadata, InterceptorClass } from './use-interceptors.decorator.js';
@@ -1 +0,0 @@
1
- export { UseInterceptors, getInterceptorsMetadata } from './use-interceptors.decorator.js';
@@ -1,7 +0,0 @@
1
- import { ExecutionContext } from '../guards/execution-context.js';
2
- export interface Interceptor {
3
- intercept(context: ExecutionContext, next: CallHandler): Promise<unknown>;
4
- }
5
- export interface CallHandler {
6
- handle(): Promise<unknown>;
7
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import 'reflect-metadata';
2
- import { Constructor } from '../types.js';
3
- import type { Interceptor } from './interceptor.interface.js';
4
- export type InterceptorClass = Constructor<Interceptor>;
5
- export declare function UseInterceptors(...interceptors: InterceptorClass[]): ClassDecorator & MethodDecorator;
6
- export declare function getInterceptorsMetadata(controllerClass: Constructor, methodName: string | symbol): InterceptorClass[];
@@ -1,19 +0,0 @@
1
- import 'reflect-metadata';
2
- import { INTERCEPTORS_METADATA } from '../constants.js';
3
- export function UseInterceptors(...interceptors) {
4
- return (target, propertyKey, descriptor) => {
5
- if (propertyKey && descriptor) {
6
- const existingInterceptors = Reflect.getMetadata(INTERCEPTORS_METADATA, target.constructor, propertyKey) ?? [];
7
- Reflect.defineMetadata(INTERCEPTORS_METADATA, [...existingInterceptors, ...interceptors], target.constructor, propertyKey);
8
- }
9
- else {
10
- const existingInterceptors = Reflect.getMetadata(INTERCEPTORS_METADATA, target) ?? [];
11
- Reflect.defineMetadata(INTERCEPTORS_METADATA, [...existingInterceptors, ...interceptors], target);
12
- }
13
- };
14
- }
15
- export function getInterceptorsMetadata(controllerClass, methodName) {
16
- const controllerInterceptors = Reflect.getMetadata(INTERCEPTORS_METADATA, controllerClass) ?? [];
17
- const methodInterceptors = Reflect.getMetadata(INTERCEPTORS_METADATA, controllerClass, methodName) ?? [];
18
- return [...controllerInterceptors, ...methodInterceptors];
19
- }