@riktajs/core 0.4.5 → 0.4.7

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 (153) hide show
  1. package/dist/core/application.d.ts +0 -29
  2. package/dist/core/application.js +0 -112
  3. package/dist/core/config/abstract-config-provider.d.ts +0 -134
  4. package/dist/core/config/abstract-config-provider.js +0 -124
  5. package/dist/core/config/env-loader.d.ts +0 -24
  6. package/dist/core/config/env-loader.js +0 -30
  7. package/dist/core/config/index.d.ts +0 -1
  8. package/dist/core/config/index.js +0 -1
  9. package/dist/core/constants.d.ts +0 -78
  10. package/dist/core/constants.js +0 -85
  11. package/dist/core/container/container.d.ts +0 -72
  12. package/dist/core/container/container.js +0 -102
  13. package/dist/core/container/index.d.ts +0 -1
  14. package/dist/core/container/index.js +0 -1
  15. package/dist/core/container/injection-token.d.ts +0 -29
  16. package/dist/core/container/injection-token.js +0 -22
  17. package/dist/core/decorators/autowired.decorator.d.ts +0 -62
  18. package/dist/core/decorators/autowired.decorator.js +0 -63
  19. package/dist/core/decorators/config-property.decorator.d.ts +0 -120
  20. package/dist/core/decorators/config-property.decorator.js +0 -140
  21. package/dist/core/decorators/controller.decorator.d.ts +0 -28
  22. package/dist/core/decorators/controller.decorator.js +0 -29
  23. package/dist/core/decorators/index.d.ts +0 -1
  24. package/dist/core/decorators/index.js +0 -2
  25. package/dist/core/decorators/injectable.decorator.d.ts +0 -23
  26. package/dist/core/decorators/injectable.decorator.js +0 -26
  27. package/dist/core/decorators/param.decorator.d.ts +0 -113
  28. package/dist/core/decorators/param.decorator.js +0 -126
  29. package/dist/core/decorators/provider.decorator.d.ts +0 -96
  30. package/dist/core/decorators/provider.decorator.js +0 -113
  31. package/dist/core/decorators/route.decorator.d.ts +0 -44
  32. package/dist/core/decorators/route.decorator.js +0 -51
  33. package/dist/core/discovery.d.ts +0 -33
  34. package/dist/core/discovery.js +4 -74
  35. package/dist/core/exceptions/catch.decorator.d.ts +0 -63
  36. package/dist/core/exceptions/catch.decorator.js +0 -59
  37. package/dist/core/exceptions/config.exceptions.d.ts +0 -12
  38. package/dist/core/exceptions/config.exceptions.js +0 -12
  39. package/dist/core/exceptions/exception-filter.d.ts +0 -96
  40. package/dist/core/exceptions/exception-filter.js +0 -53
  41. package/dist/core/exceptions/exceptions.d.ts +0 -157
  42. package/dist/core/exceptions/exceptions.js +0 -163
  43. package/dist/core/exceptions/http-exception.d.ts +0 -55
  44. package/dist/core/exceptions/http-exception.js +0 -40
  45. package/dist/core/exceptions/index.d.ts +0 -1
  46. package/dist/core/exceptions/index.js +0 -9
  47. package/dist/core/exceptions/validation.exception.d.ts +0 -41
  48. package/dist/core/exceptions/validation.exception.js +0 -34
  49. package/dist/core/guards/can-activate.interface.d.ts +0 -73
  50. package/dist/core/guards/can-activate.interface.js +0 -1
  51. package/dist/core/guards/execution-context.d.ts +0 -51
  52. package/dist/core/guards/execution-context.js +0 -6
  53. package/dist/core/guards/index.d.ts +0 -1
  54. package/dist/core/guards/index.js +0 -2
  55. package/dist/core/guards/use-guards.decorator.d.ts +0 -76
  56. package/dist/core/guards/use-guards.decorator.js +0 -78
  57. package/dist/core/index.d.ts +1 -1
  58. package/dist/core/index.js +0 -5
  59. package/dist/core/lifecycle/event-bus.d.ts +0 -44
  60. package/dist/core/lifecycle/event-bus.js +0 -30
  61. package/dist/core/lifecycle/index.d.ts +0 -1
  62. package/dist/core/lifecycle/index.js +0 -2
  63. package/dist/core/lifecycle/interfaces.d.ts +0 -91
  64. package/dist/core/lifecycle/interfaces.js +0 -8
  65. package/dist/core/lifecycle/on.decorator.d.ts +0 -51
  66. package/dist/core/lifecycle/on.decorator.js +0 -48
  67. package/dist/core/metadata.d.ts +0 -46
  68. package/dist/core/metadata.js +0 -71
  69. package/dist/core/registry.d.ts +0 -77
  70. package/dist/core/registry.js +0 -77
  71. package/dist/core/router/router.d.ts +0 -41
  72. package/dist/core/router/router.js +0 -76
  73. package/dist/core/types.d.ts +0 -109
  74. package/dist/core/types.js +0 -1
  75. package/dist/index.d.ts +0 -42
  76. package/dist/index.js +0 -44
  77. package/package.json +3 -2
  78. package/dist/core/application.d.ts.map +0 -1
  79. package/dist/core/application.js.map +0 -1
  80. package/dist/core/config/abstract-config-provider.d.ts.map +0 -1
  81. package/dist/core/config/abstract-config-provider.js.map +0 -1
  82. package/dist/core/config/env-loader.d.ts.map +0 -1
  83. package/dist/core/config/env-loader.js.map +0 -1
  84. package/dist/core/config/index.d.ts.map +0 -1
  85. package/dist/core/config/index.js.map +0 -1
  86. package/dist/core/constants.d.ts.map +0 -1
  87. package/dist/core/constants.js.map +0 -1
  88. package/dist/core/container/container.d.ts.map +0 -1
  89. package/dist/core/container/container.js.map +0 -1
  90. package/dist/core/container/index.d.ts.map +0 -1
  91. package/dist/core/container/index.js.map +0 -1
  92. package/dist/core/container/injection-token.d.ts.map +0 -1
  93. package/dist/core/container/injection-token.js.map +0 -1
  94. package/dist/core/decorators/autowired.decorator.d.ts.map +0 -1
  95. package/dist/core/decorators/autowired.decorator.js.map +0 -1
  96. package/dist/core/decorators/config-property.decorator.d.ts.map +0 -1
  97. package/dist/core/decorators/config-property.decorator.js.map +0 -1
  98. package/dist/core/decorators/controller.decorator.d.ts.map +0 -1
  99. package/dist/core/decorators/controller.decorator.js.map +0 -1
  100. package/dist/core/decorators/index.d.ts.map +0 -1
  101. package/dist/core/decorators/index.js.map +0 -1
  102. package/dist/core/decorators/injectable.decorator.d.ts.map +0 -1
  103. package/dist/core/decorators/injectable.decorator.js.map +0 -1
  104. package/dist/core/decorators/param.decorator.d.ts.map +0 -1
  105. package/dist/core/decorators/param.decorator.js.map +0 -1
  106. package/dist/core/decorators/provider.decorator.d.ts.map +0 -1
  107. package/dist/core/decorators/provider.decorator.js.map +0 -1
  108. package/dist/core/decorators/route.decorator.d.ts.map +0 -1
  109. package/dist/core/decorators/route.decorator.js.map +0 -1
  110. package/dist/core/discovery.d.ts.map +0 -1
  111. package/dist/core/discovery.js.map +0 -1
  112. package/dist/core/exceptions/catch.decorator.d.ts.map +0 -1
  113. package/dist/core/exceptions/catch.decorator.js.map +0 -1
  114. package/dist/core/exceptions/config.exceptions.d.ts.map +0 -1
  115. package/dist/core/exceptions/config.exceptions.js.map +0 -1
  116. package/dist/core/exceptions/exception-filter.d.ts.map +0 -1
  117. package/dist/core/exceptions/exception-filter.js.map +0 -1
  118. package/dist/core/exceptions/exceptions.d.ts.map +0 -1
  119. package/dist/core/exceptions/exceptions.js.map +0 -1
  120. package/dist/core/exceptions/http-exception.d.ts.map +0 -1
  121. package/dist/core/exceptions/http-exception.js.map +0 -1
  122. package/dist/core/exceptions/index.d.ts.map +0 -1
  123. package/dist/core/exceptions/index.js.map +0 -1
  124. package/dist/core/exceptions/validation.exception.d.ts.map +0 -1
  125. package/dist/core/exceptions/validation.exception.js.map +0 -1
  126. package/dist/core/guards/can-activate.interface.d.ts.map +0 -1
  127. package/dist/core/guards/can-activate.interface.js.map +0 -1
  128. package/dist/core/guards/execution-context.d.ts.map +0 -1
  129. package/dist/core/guards/execution-context.js.map +0 -1
  130. package/dist/core/guards/index.d.ts.map +0 -1
  131. package/dist/core/guards/index.js.map +0 -1
  132. package/dist/core/guards/use-guards.decorator.d.ts.map +0 -1
  133. package/dist/core/guards/use-guards.decorator.js.map +0 -1
  134. package/dist/core/index.d.ts.map +0 -1
  135. package/dist/core/index.js.map +0 -1
  136. package/dist/core/lifecycle/event-bus.d.ts.map +0 -1
  137. package/dist/core/lifecycle/event-bus.js.map +0 -1
  138. package/dist/core/lifecycle/index.d.ts.map +0 -1
  139. package/dist/core/lifecycle/index.js.map +0 -1
  140. package/dist/core/lifecycle/interfaces.d.ts.map +0 -1
  141. package/dist/core/lifecycle/interfaces.js.map +0 -1
  142. package/dist/core/lifecycle/on.decorator.d.ts.map +0 -1
  143. package/dist/core/lifecycle/on.decorator.js.map +0 -1
  144. package/dist/core/metadata.d.ts.map +0 -1
  145. package/dist/core/metadata.js.map +0 -1
  146. package/dist/core/registry.d.ts.map +0 -1
  147. package/dist/core/registry.js.map +0 -1
  148. package/dist/core/router/router.d.ts.map +0 -1
  149. package/dist/core/router/router.js.map +0 -1
  150. package/dist/core/types.d.ts.map +0 -1
  151. package/dist/core/types.js.map +0 -1
  152. package/dist/index.d.ts.map +0 -1
  153. package/dist/index.js.map +0 -1
@@ -1,53 +1,9 @@
1
1
  import 'reflect-metadata';
2
- /**
3
- * @Get() decorator - Handles HTTP GET requests
4
- *
5
- * @example
6
- * ```typescript
7
- * @Get('/users')
8
- * getUsers() { return []; }
9
- * ```
10
- */
11
2
  export declare const Get: (path?: string) => MethodDecorator;
12
- /**
13
- * @Post() decorator - Handles HTTP POST requests
14
- *
15
- * @example
16
- * ```typescript
17
- * @Post('/users')
18
- * createUser(@Body() data: CreateUserDto) { return data; }
19
- * ```
20
- */
21
3
  export declare const Post: (path?: string) => MethodDecorator;
22
- /**
23
- * @Put() decorator - Handles HTTP PUT requests
24
- */
25
4
  export declare const Put: (path?: string) => MethodDecorator;
26
- /**
27
- * @Patch() decorator - Handles HTTP PATCH requests
28
- */
29
5
  export declare const Patch: (path?: string) => MethodDecorator;
30
- /**
31
- * @Delete() decorator - Handles HTTP DELETE requests
32
- */
33
6
  export declare const Delete: (path?: string) => MethodDecorator;
34
- /**
35
- * @Options() decorator - Handles HTTP OPTIONS requests
36
- */
37
7
  export declare const Options: (path?: string) => MethodDecorator;
38
- /**
39
- * @Head() decorator - Handles HTTP HEAD requests
40
- */
41
8
  export declare const Head: (path?: string) => MethodDecorator;
42
- /**
43
- * @HttpCode() decorator - Sets the HTTP status code for a route
44
- *
45
- * @example
46
- * ```typescript
47
- * @Post('/users')
48
- * @HttpCode(201)
49
- * createUser() { return { created: true }; }
50
- * ```
51
- */
52
9
  export declare function HttpCode(statusCode: number): MethodDecorator;
53
- //# sourceMappingURL=route.decorator.d.ts.map
@@ -4,82 +4,31 @@ exports.Head = exports.Options = exports.Delete = exports.Patch = exports.Put =
4
4
  exports.HttpCode = HttpCode;
5
5
  require("reflect-metadata");
6
6
  const constants_1 = require("../constants");
7
- /**
8
- * Creates a route decorator for a specific HTTP method
9
- */
10
7
  function createRouteDecorator(method) {
11
8
  return (path = '') => {
12
9
  return (target, propertyKey, descriptor) => {
13
- // Normalize path
14
10
  const normalizedPath = path.startsWith('/') ? path : `/${path}`;
15
- // Get existing routes or initialize empty array
16
11
  const routes = Reflect.getMetadata(constants_1.ROUTES_METADATA, target.constructor) ?? [];
17
- // Add this route
18
12
  routes.push({
19
13
  method,
20
14
  path: normalizedPath === '/' ? '' : normalizedPath,
21
15
  handlerName: propertyKey,
22
16
  });
23
- // Store updated routes
24
17
  Reflect.defineMetadata(constants_1.ROUTES_METADATA, routes, target.constructor);
25
18
  return descriptor;
26
19
  };
27
20
  };
28
21
  }
29
- /**
30
- * @Get() decorator - Handles HTTP GET requests
31
- *
32
- * @example
33
- * ```typescript
34
- * @Get('/users')
35
- * getUsers() { return []; }
36
- * ```
37
- */
38
22
  exports.Get = createRouteDecorator('GET');
39
- /**
40
- * @Post() decorator - Handles HTTP POST requests
41
- *
42
- * @example
43
- * ```typescript
44
- * @Post('/users')
45
- * createUser(@Body() data: CreateUserDto) { return data; }
46
- * ```
47
- */
48
23
  exports.Post = createRouteDecorator('POST');
49
- /**
50
- * @Put() decorator - Handles HTTP PUT requests
51
- */
52
24
  exports.Put = createRouteDecorator('PUT');
53
- /**
54
- * @Patch() decorator - Handles HTTP PATCH requests
55
- */
56
25
  exports.Patch = createRouteDecorator('PATCH');
57
- /**
58
- * @Delete() decorator - Handles HTTP DELETE requests
59
- */
60
26
  exports.Delete = createRouteDecorator('DELETE');
61
- /**
62
- * @Options() decorator - Handles HTTP OPTIONS requests
63
- */
64
27
  exports.Options = createRouteDecorator('OPTIONS');
65
- /**
66
- * @Head() decorator - Handles HTTP HEAD requests
67
- */
68
28
  exports.Head = createRouteDecorator('HEAD');
69
- /**
70
- * @HttpCode() decorator - Sets the HTTP status code for a route
71
- *
72
- * @example
73
- * ```typescript
74
- * @Post('/users')
75
- * @HttpCode(201)
76
- * createUser() { return { created: true }; }
77
- * ```
78
- */
79
29
  function HttpCode(statusCode) {
80
30
  return (target, propertyKey, descriptor) => {
81
31
  Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA, statusCode, target.constructor, propertyKey);
82
32
  return descriptor;
83
33
  };
84
34
  }
85
- //# sourceMappingURL=route.decorator.js.map
@@ -1,35 +1,2 @@
1
- /**
2
- * Discover and import modules matching the given patterns
3
- *
4
- * Only imports files that contain @Controller, @Injectable, or @Provider decorators.
5
- *
6
- * @param patterns - Glob patterns or directory paths to search for files (default: ['./**'])
7
- * @param cwd - Base directory for pattern matching. If not provided, it will be
8
- * automatically resolved from the caller's location (useful when rikta-core
9
- * is used as an external library from node_modules)
10
- * @returns Promise resolving to list of imported files
11
- *
12
- * @example
13
- * ```typescript
14
- * // Scan specific directories (relative paths resolved from caller's location)
15
- * await discoverModules(['./src/controllers', './src/services']);
16
- *
17
- * // Scan with absolute path
18
- * await discoverModules(['/absolute/path/to/src']);
19
- *
20
- * // Scan everything (default)
21
- * await discoverModules();
22
- * ```
23
- */
24
1
  export declare function discoverModules(patterns?: string[], cwd?: string): Promise<string[]>;
25
- /**
26
- * Get the entry point directory (where the main script is located)
27
- *
28
- * This uses process.argv[1] to determine the directory of the script
29
- * that started the Node.js process. This works correctly when rikta-core
30
- * is installed as an external library in node_modules.
31
- *
32
- * @returns The directory of the main script, or process.cwd() as fallback
33
- */
34
2
  export declare function getCallerDirectory(): string;
35
- //# sourceMappingURL=discovery.d.ts.map
@@ -41,9 +41,6 @@ exports.getCallerDirectory = getCallerDirectory;
41
41
  const fast_glob_1 = __importDefault(require("fast-glob"));
42
42
  const promises_1 = __importDefault(require("fs/promises"));
43
43
  const path_1 = __importDefault(require("path"));
44
- /**
45
- * Default patterns to exclude from discovery
46
- */
47
44
  const DEFAULT_IGNORE_PATTERNS = [
48
45
  '**/node_modules/**',
49
46
  '**/dist/**',
@@ -53,46 +50,26 @@ const DEFAULT_IGNORE_PATTERNS = [
53
50
  '**/*.spec.ts',
54
51
  '**/*.d.ts',
55
52
  ];
56
- /**
57
- * Get the entry point directory of the application.
58
- *
59
- * Uses process.argv[1] which contains the path to the main script being executed.
60
- * This is the cleanest way to determine the user's project directory when
61
- * rikta-core is installed in node_modules.
62
- *
63
- * Falls back to process.cwd() if argv[1] is not available.
64
- */
65
53
  function getEntryPointDirectory() {
66
54
  const mainScript = process.argv[1];
67
55
  if (mainScript) {
68
- // Handle file:// URLs (ESM) and regular paths
69
56
  const filePath = mainScript.startsWith('file://')
70
57
  ? new URL(mainScript).pathname
71
58
  : mainScript;
72
59
  return path_1.default.dirname(filePath);
73
60
  }
74
- // Fallback to current working directory
75
61
  return process.cwd();
76
62
  }
77
- /**
78
- * Regex patterns to detect Rikta decorators
79
- * Supports both TypeScript source and compiled JavaScript patterns
80
- */
81
63
  const DECORATOR_PATTERNS = [
82
- // TypeScript source patterns
83
- /@Controller\s*\(/, // @Controller() or @Controller('/path')
84
- /@Injectable\s*\(/, // @Injectable() or @Injectable({ scope: 'singleton' })
85
- /@Provider\s*\(/, // @Provider(TOKEN)
86
- /@Provider\s*\(/, // @Provider(TOKEN)
87
- // Compiled JavaScript patterns (e.g., (0, core_1.Controller)('/path'))
64
+ /@Controller\s*\(/,
65
+ /@Injectable\s*\(/,
66
+ /@Provider\s*\(/,
67
+ /@Provider\s*\(/,
88
68
  /\.\s*Controller\s*\)\s*\(/,
89
69
  /\.\s*Injectable\s*\)\s*\(/,
90
70
  /\.\s*Provider\s*\)\s*\(/,
91
71
  /\.\s*ProviderConfig\s*\)\s*\(/,
92
72
  ];
93
- /**
94
- * Check if a file contains Rikta decorators (@Controller, @Injectable, or @Provider)
95
- */
96
73
  async function containsRiktaDecorators(filePath) {
97
74
  try {
98
75
  const content = await promises_1.default.readFile(filePath, 'utf-8');
@@ -102,83 +79,46 @@ async function containsRiktaDecorators(filePath) {
102
79
  return false;
103
80
  }
104
81
  }
105
- /**
106
- * Discover and import modules matching the given patterns
107
- *
108
- * Only imports files that contain @Controller, @Injectable, or @Provider decorators.
109
- *
110
- * @param patterns - Glob patterns or directory paths to search for files (default: ['./**'])
111
- * @param cwd - Base directory for pattern matching. If not provided, it will be
112
- * automatically resolved from the caller's location (useful when rikta-core
113
- * is used as an external library from node_modules)
114
- * @returns Promise resolving to list of imported files
115
- *
116
- * @example
117
- * ```typescript
118
- * // Scan specific directories (relative paths resolved from caller's location)
119
- * await discoverModules(['./src/controllers', './src/services']);
120
- *
121
- * // Scan with absolute path
122
- * await discoverModules(['/absolute/path/to/src']);
123
- *
124
- * // Scan everything (default)
125
- * await discoverModules();
126
- * ```
127
- */
128
82
  async function discoverModules(patterns = ['./**/*.{ts,js}'], cwd) {
129
- // If no cwd provided, use the entry point directory (where the main script is)
130
- // This is crucial when rikta-core is installed in node_modules
131
83
  const baseDir = cwd ?? getEntryPointDirectory();
132
- // Resolve the base directory to absolute if needed
133
84
  const absoluteBaseDir = path_1.default.isAbsolute(baseDir)
134
85
  ? baseDir
135
86
  : path_1.default.resolve(process.cwd(), baseDir);
136
- // Normalize patterns to include file extensions if not present
137
87
  const normalizedPatterns = patterns.map(pattern => {
138
- // Resolve the pattern if it's an absolute path
139
- // For absolute paths, we need to make them relative to cwd for fast-glob
140
88
  let normalizedPattern = pattern;
141
89
  if (path_1.default.isAbsolute(pattern)) {
142
- // Convert absolute path to relative from baseDir
143
90
  normalizedPattern = path_1.default.relative(absoluteBaseDir, pattern);
144
91
  if (!normalizedPattern.startsWith('.')) {
145
92
  normalizedPattern = './' + normalizedPattern;
146
93
  }
147
94
  }
148
- // If pattern already has extension, use as-is
149
95
  if (/\.\w+$/.test(normalizedPattern) || normalizedPattern.endsWith('*')) {
150
96
  return normalizedPattern;
151
97
  }
152
- // Add file extension pattern
153
98
  return normalizedPattern.endsWith('/')
154
99
  ? `${normalizedPattern}**/*.{ts,js}`
155
100
  : `${normalizedPattern}/**/*.{ts,js}`;
156
101
  });
157
- // Find all matching files
158
102
  const files = await (0, fast_glob_1.default)(normalizedPatterns, {
159
103
  cwd: absoluteBaseDir,
160
104
  absolute: true,
161
105
  ignore: DEFAULT_IGNORE_PATTERNS,
162
106
  onlyFiles: true,
163
107
  });
164
- // Filter files that contain Rikta decorators
165
108
  const riktaFiles = [];
166
109
  for (const file of files) {
167
110
  if (await containsRiktaDecorators(file)) {
168
111
  riktaFiles.push(file);
169
112
  }
170
113
  }
171
- // Import only files with decorators
172
114
  const importedFiles = [];
173
115
  for (const file of riktaFiles) {
174
116
  try {
175
- // Convert to proper import path
176
117
  const importPath = file.replace(/\.ts$/, '');
177
118
  await Promise.resolve(`${importPath}`).then(s => __importStar(require(s)));
178
119
  importedFiles.push(file);
179
120
  }
180
121
  catch (error) {
181
- // Log but don't fail - some files might have import errors
182
122
  if (process.env.DEBUG) {
183
123
  console.warn(`[Rikta] Failed to import ${file}:`, error);
184
124
  }
@@ -186,16 +126,6 @@ async function discoverModules(patterns = ['./**/*.{ts,js}'], cwd) {
186
126
  }
187
127
  return importedFiles;
188
128
  }
189
- /**
190
- * Get the entry point directory (where the main script is located)
191
- *
192
- * This uses process.argv[1] to determine the directory of the script
193
- * that started the Node.js process. This works correctly when rikta-core
194
- * is installed as an external library in node_modules.
195
- *
196
- * @returns The directory of the main script, or process.cwd() as fallback
197
- */
198
129
  function getCallerDirectory() {
199
130
  return getEntryPointDirectory();
200
131
  }
201
- //# sourceMappingURL=discovery.js.map
@@ -1,71 +1,8 @@
1
1
  import 'reflect-metadata';
2
2
  import { Constructor } from '../types';
3
- /**
4
- * Metadata key for @Catch() decorator
5
- */
6
3
  export declare const CATCH_METADATA: unique symbol;
7
- /**
8
- * Metadata stored by @Catch() decorator
9
- */
10
4
  export interface CatchMetadata {
11
- /** Exception types this filter handles */
12
5
  exceptions: Constructor<Error>[];
13
6
  }
14
- /**
15
- * @Catch() Decorator
16
- *
17
- * Marks a class as an exception filter and specifies which
18
- * exception types it should handle.
19
- *
20
- * If no exception types are provided, the filter catches all exceptions.
21
- *
22
- * @param exceptions - Exception types to catch (optional)
23
- *
24
- * @example Catch specific exception
25
- * ```typescript
26
- * @Catch(NotFoundException)
27
- * class NotFoundExceptionFilter implements ExceptionFilter {
28
- * catch(exception: NotFoundException, context: ExceptionContext) {
29
- * const { reply, path } = context;
30
- * reply.status(404).send({
31
- * statusCode: 404,
32
- * message: exception.message,
33
- * path,
34
- * timestamp: new Date().toISOString()
35
- * });
36
- * }
37
- * }
38
- * ```
39
- *
40
- * @example Catch multiple exceptions
41
- * ```typescript
42
- * @Catch(BadRequestException, UnprocessableEntityException)
43
- * class ValidationExceptionFilter implements ExceptionFilter {
44
- * catch(exception: HttpException, context: ExceptionContext) {
45
- * const { reply } = context;
46
- * const response = exception.getResponse();
47
- *
48
- * reply.status(exception.getStatus()).send({
49
- * ...response,
50
- * type: 'VALIDATION_ERROR'
51
- * });
52
- * }
53
- * }
54
- * ```
55
- *
56
- * @example Catch all exceptions
57
- * ```typescript
58
- * @Catch()
59
- * class AllExceptionsFilter implements ExceptionFilter {
60
- * catch(exception: Error, context: ExceptionContext) {
61
- * // Handle any exception
62
- * }
63
- * }
64
- * ```
65
- */
66
7
  export declare function Catch(...exceptions: Constructor<Error>[]): ClassDecorator;
67
- /**
68
- * Get catch metadata from a filter class
69
- */
70
8
  export declare function getCatchMetadata(target: Constructor): CatchMetadata | undefined;
71
- //# sourceMappingURL=catch.decorator.d.ts.map
@@ -4,62 +4,7 @@ exports.CATCH_METADATA = void 0;
4
4
  exports.Catch = Catch;
5
5
  exports.getCatchMetadata = getCatchMetadata;
6
6
  require("reflect-metadata");
7
- /**
8
- * Metadata key for @Catch() decorator
9
- */
10
7
  exports.CATCH_METADATA = Symbol('catch:metadata');
11
- /**
12
- * @Catch() Decorator
13
- *
14
- * Marks a class as an exception filter and specifies which
15
- * exception types it should handle.
16
- *
17
- * If no exception types are provided, the filter catches all exceptions.
18
- *
19
- * @param exceptions - Exception types to catch (optional)
20
- *
21
- * @example Catch specific exception
22
- * ```typescript
23
- * @Catch(NotFoundException)
24
- * class NotFoundExceptionFilter implements ExceptionFilter {
25
- * catch(exception: NotFoundException, context: ExceptionContext) {
26
- * const { reply, path } = context;
27
- * reply.status(404).send({
28
- * statusCode: 404,
29
- * message: exception.message,
30
- * path,
31
- * timestamp: new Date().toISOString()
32
- * });
33
- * }
34
- * }
35
- * ```
36
- *
37
- * @example Catch multiple exceptions
38
- * ```typescript
39
- * @Catch(BadRequestException, UnprocessableEntityException)
40
- * class ValidationExceptionFilter implements ExceptionFilter {
41
- * catch(exception: HttpException, context: ExceptionContext) {
42
- * const { reply } = context;
43
- * const response = exception.getResponse();
44
- *
45
- * reply.status(exception.getStatus()).send({
46
- * ...response,
47
- * type: 'VALIDATION_ERROR'
48
- * });
49
- * }
50
- * }
51
- * ```
52
- *
53
- * @example Catch all exceptions
54
- * ```typescript
55
- * @Catch()
56
- * class AllExceptionsFilter implements ExceptionFilter {
57
- * catch(exception: Error, context: ExceptionContext) {
58
- * // Handle any exception
59
- * }
60
- * }
61
- * ```
62
- */
63
8
  function Catch(...exceptions) {
64
9
  return (target) => {
65
10
  const metadata = {
@@ -68,10 +13,6 @@ function Catch(...exceptions) {
68
13
  Reflect.defineMetadata(exports.CATCH_METADATA, metadata, target);
69
14
  };
70
15
  }
71
- /**
72
- * Get catch metadata from a filter class
73
- */
74
16
  function getCatchMetadata(target) {
75
17
  return Reflect.getMetadata(exports.CATCH_METADATA, target);
76
18
  }
77
- //# sourceMappingURL=catch.decorator.js.map
@@ -1,21 +1,9 @@
1
- /**
2
- * Exception thrown when attempting to register a config provider with a token
3
- * that is already registered.
4
- */
5
1
  export declare class ConfigProviderAlreadyRegisteredException extends Error {
6
2
  constructor(token: string, existingClass: string, newClass: string);
7
3
  }
8
- /**
9
- * Exception thrown when attempting to retrieve a config provider that
10
- * has not been registered.
11
- */
12
4
  export declare class ConfigProviderNotFoundException extends Error {
13
5
  constructor(token: string, availableTokens?: string[]);
14
6
  }
15
- /**
16
- * Exception thrown when a config provider fails to instantiate.
17
- */
18
7
  export declare class ConfigProviderInstantiationException extends Error {
19
8
  constructor(token: string, className: string, cause: Error);
20
9
  }
21
- //# sourceMappingURL=config.exceptions.d.ts.map
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigProviderInstantiationException = exports.ConfigProviderNotFoundException = exports.ConfigProviderAlreadyRegisteredException = void 0;
4
- /**
5
- * Exception thrown when attempting to register a config provider with a token
6
- * that is already registered.
7
- */
8
4
  class ConfigProviderAlreadyRegisteredException extends Error {
9
5
  constructor(token, existingClass, newClass) {
10
6
  super(`Config provider with token "${token}" is already registered.\n` +
@@ -15,10 +11,6 @@ class ConfigProviderAlreadyRegisteredException extends Error {
15
11
  }
16
12
  }
17
13
  exports.ConfigProviderAlreadyRegisteredException = ConfigProviderAlreadyRegisteredException;
18
- /**
19
- * Exception thrown when attempting to retrieve a config provider that
20
- * has not been registered.
21
- */
22
14
  class ConfigProviderNotFoundException extends Error {
23
15
  constructor(token, availableTokens = []) {
24
16
  const suggestion = availableTokens.length > 0
@@ -33,9 +25,6 @@ class ConfigProviderNotFoundException extends Error {
33
25
  }
34
26
  }
35
27
  exports.ConfigProviderNotFoundException = ConfigProviderNotFoundException;
36
- /**
37
- * Exception thrown when a config provider fails to instantiate.
38
- */
39
28
  class ConfigProviderInstantiationException extends Error {
40
29
  constructor(token, className, cause) {
41
30
  super(`Failed to instantiate config provider "${className}" (token: "${token}").\n` +
@@ -49,4 +38,3 @@ class ConfigProviderInstantiationException extends Error {
49
38
  }
50
39
  }
51
40
  exports.ConfigProviderInstantiationException = ConfigProviderInstantiationException;
52
- //# sourceMappingURL=config.exceptions.js.map
@@ -1,134 +1,38 @@
1
1
  import type { FastifyRequest, FastifyReply, FastifyError } from 'fastify';
2
- /**
3
- * Exception context passed to filters
4
- */
5
2
  export interface ExceptionContext {
6
- /** The caught exception */
7
3
  exception: Error;
8
- /** Fastify request object */
9
4
  request: FastifyRequest;
10
- /** Fastify reply object */
11
5
  reply: FastifyReply;
12
- /** Request path */
13
6
  path: string;
14
- /** HTTP method */
15
7
  method: string;
16
- /** Request ID (if available) */
17
8
  requestId?: string;
18
9
  }
19
- /**
20
- * Exception Filter Interface
21
- *
22
- * Implement this interface to create custom exception handlers.
23
- * Filters can catch specific exception types or handle all exceptions.
24
- *
25
- * @example
26
- * ```typescript
27
- * @Catch(ValidationException)
28
- * class ValidationExceptionFilter implements ExceptionFilter {
29
- * catch(exception: ValidationException, context: ExceptionContext) {
30
- * const { reply } = context;
31
- * reply.status(422).send({
32
- * statusCode: 422,
33
- * errors: exception.errors,
34
- * timestamp: new Date().toISOString()
35
- * });
36
- * }
37
- * }
38
- * ```
39
- */
40
10
  export interface ExceptionFilter<T extends Error = Error> {
41
- /**
42
- * Handle the caught exception
43
- *
44
- * @param exception - The caught exception
45
- * @param context - Exception context with request/reply
46
- */
47
11
  catch(exception: T, context: ExceptionContext): void | Promise<void>;
48
12
  }
49
- /**
50
- * Standard error response format
51
- */
52
13
  export interface ErrorResponse {
53
- /** HTTP status code */
54
14
  statusCode: number;
55
- /** Error message */
56
15
  message: string;
57
- /** Error type/name (e.g., "Bad Request", "Not Found") */
58
16
  error: string;
59
- /** ISO timestamp when the error occurred */
60
17
  timestamp: string;
61
- /** Request path that caused the error */
62
18
  path: string;
63
- /** Request ID for tracing (optional) */
64
19
  requestId?: string;
65
- /** Additional error details (optional) */
66
20
  details?: unknown;
67
- /** Application-specific error code (optional) */
68
21
  code?: string;
69
- /** Stack trace (only in development mode) */
70
22
  stack?: string;
71
23
  }
72
- /**
73
- * Global Exception Filter
74
- *
75
- * Default exception handler that catches all errors and returns
76
- * a standardized JSON response.
77
- *
78
- * Features:
79
- * - Handles HttpException with proper status codes
80
- * - Handles Fastify validation errors
81
- * - Handles unknown errors as 500 Internal Server Error
82
- * - Includes stack traces in development mode
83
- *
84
- * @example
85
- * ```typescript
86
- * // The filter is automatically registered by Rikta
87
- * // But you can customize behavior via options:
88
- * const app = await Rikta.create({
89
- * exceptionFilter: {
90
- * includeStack: process.env.NODE_ENV !== 'production',
91
- * logErrors: true
92
- * }
93
- * });
94
- * ```
95
- */
96
24
  export declare class GlobalExceptionFilter implements ExceptionFilter {
97
25
  private readonly includeStack;
98
26
  private readonly logErrors;
99
27
  constructor(options?: GlobalExceptionFilterOptions);
100
- /**
101
- * Handle any exception and send standardized response
102
- */
103
28
  catch(exception: Error, context: ExceptionContext): void;
104
- /**
105
- * Build standardized error response
106
- */
107
29
  private buildResponse;
108
- /**
109
- * Check if error is a Fastify validation error
110
- */
111
30
  private isFastifyValidationError;
112
- /**
113
- * Check if error is a Fastify error with statusCode
114
- */
115
31
  private isFastifyError;
116
- /**
117
- * Log error to console
118
- */
119
32
  private logError;
120
33
  }
121
- /**
122
- * Options for GlobalExceptionFilter
123
- */
124
34
  export interface GlobalExceptionFilterOptions {
125
- /** Include stack trace in response (default: true in development) */
126
35
  includeStack?: boolean;
127
- /** Log errors to console (default: true) */
128
36
  logErrors?: boolean;
129
37
  }
130
- /**
131
- * Create exception handler function for Fastify
132
- */
133
38
  export declare function createExceptionHandler(filter: ExceptionFilter, customFilters?: Map<Function, ExceptionFilter>): (error: FastifyError | Error, request: FastifyRequest, reply: FastifyReply) => Promise<void>;
134
- //# sourceMappingURL=exception-filter.d.ts.map