@riktajs/core 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +132 -54
  2. package/dist/core/application.d.ts +1 -1
  3. package/dist/core/application.js +51 -45
  4. package/dist/core/config/abstract-config-provider.js +8 -13
  5. package/dist/core/config/env-loader.js +12 -17
  6. package/dist/core/config/index.d.ts +2 -2
  7. package/dist/core/config/index.js +2 -18
  8. package/dist/core/constants.js +18 -21
  9. package/dist/core/container/abstract-class.utils.d.ts +1 -1
  10. package/dist/core/container/abstract-class.utils.js +14 -24
  11. package/dist/core/container/container.d.ts +2 -2
  12. package/dist/core/container/container.js +47 -19
  13. package/dist/core/container/implements.decorator.d.ts +1 -1
  14. package/dist/core/container/implements.decorator.js +17 -23
  15. package/dist/core/container/index.d.ts +5 -4
  16. package/dist/core/container/index.js +5 -20
  17. package/dist/core/container/injection-token.js +1 -5
  18. package/dist/core/container/request-scope.d.ts +16 -0
  19. package/dist/core/container/request-scope.js +49 -0
  20. package/dist/core/decorators/apply-decorators.js +3 -7
  21. package/dist/core/decorators/autowired.decorator.d.ts +1 -1
  22. package/dist/core/decorators/autowired.decorator.js +12 -16
  23. package/dist/core/decorators/config-property.decorator.js +9 -15
  24. package/dist/core/decorators/controller.decorator.js +9 -12
  25. package/dist/core/decorators/create-param-decorator.d.ts +1 -1
  26. package/dist/core/decorators/create-param-decorator.js +7 -12
  27. package/dist/core/decorators/index.d.ts +9 -9
  28. package/dist/core/decorators/index.js +9 -25
  29. package/dist/core/decorators/injectable.decorator.d.ts +1 -1
  30. package/dist/core/decorators/injectable.decorator.js +8 -11
  31. package/dist/core/decorators/param.decorator.d.ts +1 -1
  32. package/dist/core/decorators/param.decorator.js +14 -17
  33. package/dist/core/decorators/provider.decorator.d.ts +2 -2
  34. package/dist/core/decorators/provider.decorator.js +12 -17
  35. package/dist/core/decorators/route.decorator.js +13 -17
  36. package/dist/core/discovery.d.ts +2 -1
  37. package/dist/core/discovery.js +44 -64
  38. package/dist/core/exceptions/catch.decorator.d.ts +1 -1
  39. package/dist/core/exceptions/catch.decorator.js +6 -11
  40. package/dist/core/exceptions/config.exceptions.js +3 -9
  41. package/dist/core/exceptions/discovery.exception.d.ts +18 -0
  42. package/dist/core/exceptions/discovery.exception.js +39 -0
  43. package/dist/core/exceptions/exception-filter.js +5 -10
  44. package/dist/core/exceptions/exceptions.d.ts +1 -1
  45. package/dist/core/exceptions/exceptions.js +19 -40
  46. package/dist/core/exceptions/http-exception.js +1 -5
  47. package/dist/core/exceptions/index.d.ts +7 -6
  48. package/dist/core/exceptions/index.js +7 -37
  49. package/dist/core/exceptions/validation.exception.d.ts +1 -1
  50. package/dist/core/exceptions/validation.exception.js +2 -6
  51. package/dist/core/guards/can-activate.interface.d.ts +1 -1
  52. package/dist/core/guards/can-activate.interface.js +1 -2
  53. package/dist/core/guards/execution-context.d.ts +8 -1
  54. package/dist/core/guards/execution-context.js +9 -5
  55. package/dist/core/guards/index.d.ts +3 -3
  56. package/dist/core/guards/index.js +2 -8
  57. package/dist/core/guards/use-guards.decorator.d.ts +2 -2
  58. package/dist/core/guards/use-guards.decorator.js +10 -14
  59. package/dist/core/index.d.ts +16 -14
  60. package/dist/core/index.js +17 -33
  61. package/dist/core/interceptors/index.d.ts +2 -0
  62. package/dist/core/interceptors/index.js +1 -0
  63. package/dist/core/interceptors/interceptor.interface.d.ts +7 -0
  64. package/dist/core/interceptors/interceptor.interface.js +1 -0
  65. package/dist/core/interceptors/use-interceptors.decorator.d.ts +6 -0
  66. package/dist/core/interceptors/use-interceptors.decorator.js +19 -0
  67. package/dist/core/lifecycle/event-bus.d.ts +10 -5
  68. package/dist/core/lifecycle/event-bus.js +61 -14
  69. package/dist/core/lifecycle/index.d.ts +3 -3
  70. package/dist/core/lifecycle/index.js +3 -19
  71. package/dist/core/lifecycle/interfaces.js +1 -2
  72. package/dist/core/lifecycle/on.decorator.d.ts +1 -1
  73. package/dist/core/lifecycle/on.decorator.js +5 -9
  74. package/dist/core/metadata.d.ts +2 -2
  75. package/dist/core/metadata.js +26 -43
  76. package/dist/core/middleware/index.d.ts +3 -3
  77. package/dist/core/middleware/index.js +2 -9
  78. package/dist/core/middleware/middleware.decorator.js +2 -5
  79. package/dist/core/middleware/rikta-middleware.interface.js +1 -2
  80. package/dist/core/middleware/use-middleware.decorator.d.ts +2 -2
  81. package/dist/core/middleware/use-middleware.decorator.js +10 -14
  82. package/dist/core/profiler/index.d.ts +2 -0
  83. package/dist/core/profiler/index.js +1 -0
  84. package/dist/core/profiler/performance-profiler.d.ts +42 -0
  85. package/dist/core/profiler/performance-profiler.js +95 -0
  86. package/dist/core/registry.d.ts +1 -3
  87. package/dist/core/registry.js +4 -39
  88. package/dist/core/router/router.d.ts +12 -2
  89. package/dist/core/router/router.js +112 -39
  90. package/dist/core/types.d.ts +8 -4
  91. package/dist/core/types.js +1 -2
  92. package/dist/index.d.ts +2 -2
  93. package/dist/index.js +2 -20
  94. package/package.json +8 -1
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Context = exports.Ctx = exports.Reply = exports.Res = exports.Request = exports.Req = exports.Headers = exports.Param = exports.Query = exports.Body = void 0;
4
- require("reflect-metadata");
5
- const constants_1 = require("../constants");
1
+ import 'reflect-metadata';
2
+ import { PARAM_METADATA, ParamType } from '../constants.js';
6
3
  function isZodType(value) {
7
4
  return (value !== null &&
8
5
  typeof value === 'object' &&
@@ -15,7 +12,7 @@ function createParamDecorator(type) {
15
12
  return (target, propertyKey, parameterIndex) => {
16
13
  if (propertyKey === undefined)
17
14
  return;
18
- const existingParams = Reflect.getMetadata(constants_1.PARAM_METADATA, target.constructor, propertyKey) ?? [];
15
+ const existingParams = Reflect.getMetadata(PARAM_METADATA, target.constructor, propertyKey) ?? [];
19
16
  const isSchema = isZodType(keyOrSchema);
20
17
  const metadata = {
21
18
  index: parameterIndex,
@@ -24,18 +21,18 @@ function createParamDecorator(type) {
24
21
  zodSchema: isSchema ? keyOrSchema : undefined,
25
22
  };
26
23
  existingParams.push(metadata);
27
- Reflect.defineMetadata(constants_1.PARAM_METADATA, existingParams, target.constructor, propertyKey);
24
+ Reflect.defineMetadata(PARAM_METADATA, existingParams, target.constructor, propertyKey);
28
25
  };
29
26
  }
30
27
  return decorator;
31
28
  }
32
- exports.Body = createParamDecorator(constants_1.ParamType.BODY);
33
- exports.Query = createParamDecorator(constants_1.ParamType.QUERY);
34
- exports.Param = createParamDecorator(constants_1.ParamType.PARAM);
35
- exports.Headers = createParamDecorator(constants_1.ParamType.HEADERS);
36
- exports.Req = createParamDecorator(constants_1.ParamType.REQUEST);
37
- exports.Request = exports.Req;
38
- exports.Res = createParamDecorator(constants_1.ParamType.REPLY);
39
- exports.Reply = exports.Res;
40
- exports.Ctx = createParamDecorator(constants_1.ParamType.CONTEXT);
41
- exports.Context = exports.Ctx;
29
+ export const Body = createParamDecorator(ParamType.BODY);
30
+ export const Query = createParamDecorator(ParamType.QUERY);
31
+ export const Param = createParamDecorator(ParamType.PARAM);
32
+ export const Headers = createParamDecorator(ParamType.HEADERS);
33
+ export const Req = createParamDecorator(ParamType.REQUEST);
34
+ export const Request = Req;
35
+ export const Res = createParamDecorator(ParamType.REPLY);
36
+ export const Reply = Res;
37
+ export const Ctx = createParamDecorator(ParamType.CONTEXT);
38
+ export const Context = Ctx;
@@ -1,6 +1,6 @@
1
1
  import 'reflect-metadata';
2
- import { Token } from '../container/injection-token';
3
- import { Constructor } from '../types';
2
+ import { Token } from '../container/injection-token.js';
3
+ import { Constructor } from '../types.js';
4
4
  export interface ProviderMetadata {
5
5
  token: Token;
6
6
  }
@@ -1,11 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Provider = Provider;
4
- exports.getConfigProviderMetadata = getConfigProviderMetadata;
5
- exports.isConfigProvider = isConfigProvider;
6
- require("reflect-metadata");
7
- const constants_1 = require("../constants");
8
- const registry_1 = require("../registry");
1
+ import 'reflect-metadata';
2
+ import { PROVIDER_METADATA, CONFIG_PROVIDER_METADATA } from '../constants.js';
3
+ import { registry } from '../registry.js';
9
4
  function generateTokenFromClassName(className) {
10
5
  let tokenName = className.replace(/Provider$/, '');
11
6
  tokenName = tokenName
@@ -17,7 +12,7 @@ function generateTokenFromClassName(className) {
17
12
  }
18
13
  return tokenName;
19
14
  }
20
- function Provider(token) {
15
+ export function Provider(token) {
21
16
  return (target) => {
22
17
  const className = target.name;
23
18
  const isConfigProvider = typeof target.prototype.schema === 'function';
@@ -40,22 +35,22 @@ function Provider(token) {
40
35
  `Use "${configToken.toUpperCase()}" instead.`);
41
36
  }
42
37
  const configMetadata = { token: configToken };
43
- Reflect.defineMetadata(constants_1.CONFIG_PROVIDER_METADATA, configMetadata, target);
44
- registry_1.registry.registerConfigProvider(configToken, target);
38
+ Reflect.defineMetadata(CONFIG_PROVIDER_METADATA, configMetadata, target);
39
+ registry.registerConfigProvider(configToken, target);
45
40
  }
46
41
  else {
47
42
  if (token === undefined) {
48
43
  throw new Error(`@Provider: Custom provider "${className}" requires a token parameter.`);
49
44
  }
50
45
  const metadata = { token };
51
- Reflect.defineMetadata(constants_1.PROVIDER_METADATA, metadata, target);
52
- registry_1.registry.registerCustomProvider(target);
46
+ Reflect.defineMetadata(PROVIDER_METADATA, metadata, target);
47
+ registry.registerCustomProvider(target);
53
48
  }
54
49
  };
55
50
  }
56
- function getConfigProviderMetadata(target) {
57
- return Reflect.getMetadata(constants_1.CONFIG_PROVIDER_METADATA, target);
51
+ export function getConfigProviderMetadata(target) {
52
+ return Reflect.getMetadata(CONFIG_PROVIDER_METADATA, target);
58
53
  }
59
- function isConfigProvider(target) {
60
- return Reflect.hasMetadata(constants_1.CONFIG_PROVIDER_METADATA, target);
54
+ export function isConfigProvider(target) {
55
+ return Reflect.hasMetadata(CONFIG_PROVIDER_METADATA, target);
61
56
  }
@@ -1,34 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Head = exports.Options = exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = void 0;
4
- exports.HttpCode = HttpCode;
5
- require("reflect-metadata");
6
- const constants_1 = require("../constants");
1
+ import 'reflect-metadata';
2
+ import { ROUTES_METADATA, HTTP_CODE_METADATA } from '../constants.js';
7
3
  function createRouteDecorator(method) {
8
4
  return (path = '') => {
9
5
  return (target, propertyKey, descriptor) => {
10
6
  const normalizedPath = path.startsWith('/') ? path : `/${path}`;
11
- const routes = Reflect.getMetadata(constants_1.ROUTES_METADATA, target.constructor) ?? [];
7
+ const routes = Reflect.getMetadata(ROUTES_METADATA, target.constructor) ?? [];
12
8
  routes.push({
13
9
  method,
14
10
  path: normalizedPath === '/' ? '' : normalizedPath,
15
11
  handlerName: propertyKey,
16
12
  });
17
- Reflect.defineMetadata(constants_1.ROUTES_METADATA, routes, target.constructor);
13
+ Reflect.defineMetadata(ROUTES_METADATA, routes, target.constructor);
18
14
  return descriptor;
19
15
  };
20
16
  };
21
17
  }
22
- exports.Get = createRouteDecorator('GET');
23
- exports.Post = createRouteDecorator('POST');
24
- exports.Put = createRouteDecorator('PUT');
25
- exports.Patch = createRouteDecorator('PATCH');
26
- exports.Delete = createRouteDecorator('DELETE');
27
- exports.Options = createRouteDecorator('OPTIONS');
28
- exports.Head = createRouteDecorator('HEAD');
29
- function HttpCode(statusCode) {
18
+ export const Get = createRouteDecorator('GET');
19
+ export const Post = createRouteDecorator('POST');
20
+ export const Put = createRouteDecorator('PUT');
21
+ export const Patch = createRouteDecorator('PATCH');
22
+ export const Delete = createRouteDecorator('DELETE');
23
+ export const Options = createRouteDecorator('OPTIONS');
24
+ export const Head = createRouteDecorator('HEAD');
25
+ export function HttpCode(statusCode) {
30
26
  return (target, propertyKey, descriptor) => {
31
- Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA, statusCode, target.constructor, propertyKey);
27
+ Reflect.defineMetadata(HTTP_CODE_METADATA, statusCode, target.constructor, propertyKey);
32
28
  return descriptor;
33
29
  };
34
30
  }
@@ -1,2 +1,3 @@
1
- export declare function discoverModules(patterns?: string[], cwd?: string): Promise<string[]>;
1
+ import { DiscoveryOptions } from './exceptions/discovery.exception.js';
2
+ export declare function discoverModules(optionsOrPatterns?: DiscoveryOptions | string[], cwd?: string): Promise<string[]>;
2
3
  export declare function getCallerDirectory(): string;
@@ -1,46 +1,7 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.discoverModules = discoverModules;
40
- exports.getCallerDirectory = getCallerDirectory;
41
- const fast_glob_1 = __importDefault(require("fast-glob"));
42
- const promises_1 = __importDefault(require("fs/promises"));
43
- const path_1 = __importDefault(require("path"));
1
+ import fg from 'fast-glob';
2
+ import fs from 'fs/promises';
3
+ import path from 'path';
4
+ import { DiscoveryException } from './exceptions/discovery.exception.js';
44
5
  const DEFAULT_IGNORE_PATTERNS = [
45
6
  '**/node_modules/**',
46
7
  '**/dist/**',
@@ -56,7 +17,7 @@ function getEntryPointDirectory() {
56
17
  const filePath = mainScript.startsWith('file://')
57
18
  ? new URL(mainScript).pathname
58
19
  : mainScript;
59
- return path_1.default.dirname(filePath);
20
+ return path.dirname(filePath);
60
21
  }
61
22
  return process.cwd();
62
23
  }
@@ -64,30 +25,38 @@ const DECORATOR_PATTERNS = [
64
25
  /@Controller\s*\(/,
65
26
  /@Injectable\s*\(/,
66
27
  /@Provider\s*\(/,
67
- /@Provider\s*\(/,
68
28
  /\.\s*Controller\s*\)\s*\(/,
69
29
  /\.\s*Injectable\s*\)\s*\(/,
70
30
  /\.\s*Provider\s*\)\s*\(/,
71
31
  /\.\s*ProviderConfig\s*\)\s*\(/,
32
+ /import\s*{\s*[^}]*\bController\b[^}]*}\s*from\s*['"]@riktajs\/core['"]/,
33
+ /import\s*{\s*[^}]*\bInjectable\b[^}]*}\s*from\s*['"]@riktajs\/core['"]/,
34
+ /import\s*{\s*[^}]*\bProvider\b[^}]*}\s*from\s*['"]@riktajs\/core['"]/,
72
35
  ];
73
36
  async function containsRiktaDecorators(filePath) {
74
37
  try {
75
- const content = await promises_1.default.readFile(filePath, 'utf-8');
38
+ const content = await fs.readFile(filePath, 'utf-8');
76
39
  return DECORATOR_PATTERNS.some(pattern => pattern.test(content));
77
40
  }
78
41
  catch {
79
42
  return false;
80
43
  }
81
44
  }
82
- async function discoverModules(patterns = ['./**/*.{ts,js}'], cwd) {
83
- const baseDir = cwd ?? getEntryPointDirectory();
84
- const absoluteBaseDir = path_1.default.isAbsolute(baseDir)
45
+ export async function discoverModules(optionsOrPatterns = ['./**/*.{ts,js}'], cwd) {
46
+ const options = Array.isArray(optionsOrPatterns)
47
+ ? { patterns: optionsOrPatterns, cwd }
48
+ : optionsOrPatterns;
49
+ const patterns = options.patterns ?? ['./**/*.{ts,js}'];
50
+ const strict = options.strict ?? false;
51
+ const onImportError = options.onImportError;
52
+ const baseDir = options.cwd ?? cwd ?? getEntryPointDirectory();
53
+ const absoluteBaseDir = path.isAbsolute(baseDir)
85
54
  ? baseDir
86
- : path_1.default.resolve(process.cwd(), baseDir);
55
+ : path.resolve(process.cwd(), baseDir);
87
56
  const normalizedPatterns = patterns.map(pattern => {
88
57
  let normalizedPattern = pattern;
89
- if (path_1.default.isAbsolute(pattern)) {
90
- normalizedPattern = path_1.default.relative(absoluteBaseDir, pattern);
58
+ if (path.isAbsolute(pattern)) {
59
+ normalizedPattern = path.relative(absoluteBaseDir, pattern);
91
60
  if (!normalizedPattern.startsWith('.')) {
92
61
  normalizedPattern = './' + normalizedPattern;
93
62
  }
@@ -99,33 +68,44 @@ async function discoverModules(patterns = ['./**/*.{ts,js}'], cwd) {
99
68
  ? `${normalizedPattern}**/*.{ts,js}`
100
69
  : `${normalizedPattern}/**/*.{ts,js}`;
101
70
  });
102
- const files = await (0, fast_glob_1.default)(normalizedPatterns, {
71
+ const files = await fg(normalizedPatterns, {
103
72
  cwd: absoluteBaseDir,
104
73
  absolute: true,
105
74
  ignore: DEFAULT_IGNORE_PATTERNS,
106
75
  onlyFiles: true,
107
76
  });
108
- const riktaFiles = [];
109
- for (const file of files) {
110
- if (await containsRiktaDecorators(file)) {
111
- riktaFiles.push(file);
112
- }
113
- }
77
+ const decoratorChecks = await Promise.all(files.map(async (file) => ({ file, hasDecorators: await containsRiktaDecorators(file) })));
78
+ const riktaFiles = decoratorChecks
79
+ .filter(({ hasDecorators }) => hasDecorators)
80
+ .map(({ file }) => file);
114
81
  const importedFiles = [];
82
+ const failedImports = [];
115
83
  for (const file of riktaFiles) {
116
84
  try {
117
- const importPath = file.replace(/\.ts$/, '');
118
- await Promise.resolve(`${importPath}`).then(s => __importStar(require(s)));
85
+ let importPath;
86
+ if (file.endsWith('.js')) {
87
+ importPath = `file://${file}`;
88
+ }
89
+ else {
90
+ importPath = file.replace(/\.ts$/, '');
91
+ }
92
+ await import(importPath);
119
93
  importedFiles.push(file);
120
94
  }
121
- catch (error) {
95
+ catch (err) {
96
+ const error = err instanceof Error ? err : new Error(String(err));
97
+ onImportError?.(file, error);
122
98
  if (process.env.DEBUG) {
123
- console.warn(`[Rikta] Failed to import ${file}:`, error);
99
+ console.warn(`[Rikta] Failed to import ${file}:`, error.message);
124
100
  }
101
+ failedImports.push({ filePath: file, error });
125
102
  }
126
103
  }
104
+ if (strict && failedImports.length > 0) {
105
+ throw new DiscoveryException(failedImports);
106
+ }
127
107
  return importedFiles;
128
108
  }
129
- function getCallerDirectory() {
109
+ export function getCallerDirectory() {
130
110
  return getEntryPointDirectory();
131
111
  }
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { Constructor } from '../types';
2
+ import { Constructor } from '../types.js';
3
3
  export declare const CATCH_METADATA: unique symbol;
4
4
  export interface CatchMetadata {
5
5
  exceptions: Constructor<Error>[];
@@ -1,18 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CATCH_METADATA = void 0;
4
- exports.Catch = Catch;
5
- exports.getCatchMetadata = getCatchMetadata;
6
- require("reflect-metadata");
7
- exports.CATCH_METADATA = Symbol('catch:metadata');
8
- function Catch(...exceptions) {
1
+ import 'reflect-metadata';
2
+ export const CATCH_METADATA = Symbol('catch:metadata');
3
+ export function Catch(...exceptions) {
9
4
  return (target) => {
10
5
  const metadata = {
11
6
  exceptions: exceptions.length > 0 ? exceptions : [],
12
7
  };
13
- Reflect.defineMetadata(exports.CATCH_METADATA, metadata, target);
8
+ Reflect.defineMetadata(CATCH_METADATA, metadata, target);
14
9
  };
15
10
  }
16
- function getCatchMetadata(target) {
17
- return Reflect.getMetadata(exports.CATCH_METADATA, target);
11
+ export function getCatchMetadata(target) {
12
+ return Reflect.getMetadata(CATCH_METADATA, target);
18
13
  }
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfigProviderInstantiationException = exports.ConfigProviderNotFoundException = exports.ConfigProviderAlreadyRegisteredException = void 0;
4
- class ConfigProviderAlreadyRegisteredException extends Error {
1
+ export class ConfigProviderAlreadyRegisteredException extends Error {
5
2
  constructor(token, existingClass, newClass) {
6
3
  super(`Config provider with token "${token}" is already registered.\n` +
7
4
  `Existing: ${existingClass}\n` +
@@ -10,8 +7,7 @@ class ConfigProviderAlreadyRegisteredException extends Error {
10
7
  this.name = 'ConfigProviderAlreadyRegisteredException';
11
8
  }
12
9
  }
13
- exports.ConfigProviderAlreadyRegisteredException = ConfigProviderAlreadyRegisteredException;
14
- class ConfigProviderNotFoundException extends Error {
10
+ export class ConfigProviderNotFoundException extends Error {
15
11
  constructor(token, availableTokens = []) {
16
12
  const suggestion = availableTokens.length > 0
17
13
  ? `\n\nAvailable tokens: ${availableTokens.join(', ')}`
@@ -24,8 +20,7 @@ class ConfigProviderNotFoundException extends Error {
24
20
  this.name = 'ConfigProviderNotFoundException';
25
21
  }
26
22
  }
27
- exports.ConfigProviderNotFoundException = ConfigProviderNotFoundException;
28
- class ConfigProviderInstantiationException extends Error {
23
+ export class ConfigProviderInstantiationException extends Error {
29
24
  constructor(token, className, cause) {
30
25
  super(`Failed to instantiate config provider "${className}" (token: "${token}").\n` +
31
26
  `Cause: ${cause.message}\n\n` +
@@ -37,4 +32,3 @@ class ConfigProviderInstantiationException extends Error {
37
32
  this.cause = cause;
38
33
  }
39
34
  }
40
- exports.ConfigProviderInstantiationException = ConfigProviderInstantiationException;
@@ -0,0 +1,18 @@
1
+ export declare class DiscoveryException extends Error {
2
+ readonly filePath: string;
3
+ readonly originalError: Error;
4
+ readonly failedImports: DiscoveryFailure[];
5
+ constructor(filePath: string, originalError: Error);
6
+ constructor(failures: DiscoveryFailure[]);
7
+ getReport(): string;
8
+ }
9
+ export interface DiscoveryFailure {
10
+ filePath: string;
11
+ error: Error;
12
+ }
13
+ export interface DiscoveryOptions {
14
+ patterns?: string[];
15
+ cwd?: string;
16
+ strict?: boolean;
17
+ onImportError?: (filePath: string, error: Error) => void;
18
+ }
@@ -0,0 +1,39 @@
1
+ export class DiscoveryException extends Error {
2
+ filePath;
3
+ originalError;
4
+ failedImports;
5
+ constructor(filePathOrFailures, originalError) {
6
+ if (typeof filePathOrFailures === 'string') {
7
+ const filePath = filePathOrFailures;
8
+ const error = originalError;
9
+ super(`[Rikta Discovery] Failed to import module: ${filePath}\n` +
10
+ `Reason: ${error.message}`);
11
+ this.filePath = filePath;
12
+ this.originalError = error;
13
+ this.failedImports = [{ filePath, error }];
14
+ }
15
+ else {
16
+ const failures = filePathOrFailures;
17
+ const fileList = failures.map(f => ` - ${f.filePath}: ${f.error.message}`).join('\n');
18
+ super(`[Rikta Discovery] Failed to import ${failures.length} module(s):\n${fileList}`);
19
+ this.filePath = failures[0]?.filePath ?? '';
20
+ this.originalError = failures[0]?.error ?? new Error('Unknown error');
21
+ this.failedImports = failures;
22
+ }
23
+ this.name = 'DiscoveryException';
24
+ Error.captureStackTrace(this, this.constructor);
25
+ }
26
+ getReport() {
27
+ const lines = ['Discovery Failures:', ''];
28
+ for (const { filePath, error } of this.failedImports) {
29
+ lines.push(`📁 ${filePath}`);
30
+ lines.push(` Error: ${error.message}`);
31
+ if (error.stack) {
32
+ const stackLines = error.stack.split('\n').slice(1, 4);
33
+ lines.push(` Stack: ${stackLines.join('\n ')}`);
34
+ }
35
+ lines.push('');
36
+ }
37
+ return lines.join('\n');
38
+ }
39
+ }
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GlobalExceptionFilter = void 0;
4
- exports.createExceptionHandler = createExceptionHandler;
5
- const http_exception_1 = require("./http-exception");
6
- class GlobalExceptionFilter {
1
+ import { HttpException } from './http-exception.js';
2
+ export class GlobalExceptionFilter {
7
3
  includeStack;
8
4
  logErrors;
9
5
  constructor(options = {}) {
@@ -20,7 +16,7 @@ class GlobalExceptionFilter {
20
16
  reply.status(response.statusCode).send(response);
21
17
  }
22
18
  buildResponse(exception, path, requestId) {
23
- if (exception instanceof http_exception_1.HttpException) {
19
+ if (exception instanceof HttpException) {
24
20
  const httpResponse = exception.getResponse();
25
21
  return {
26
22
  statusCode: httpResponse.statusCode,
@@ -76,7 +72,7 @@ class GlobalExceptionFilter {
76
72
  }
77
73
  logError(exception, method, path, requestId) {
78
74
  const timestamp = new Date().toISOString();
79
- const status = exception instanceof http_exception_1.HttpException
75
+ const status = exception instanceof HttpException
80
76
  ? exception.getStatus()
81
77
  : 500;
82
78
  const prefix = status >= 500 ? '❌' : '⚠️';
@@ -87,8 +83,7 @@ class GlobalExceptionFilter {
87
83
  }
88
84
  }
89
85
  }
90
- exports.GlobalExceptionFilter = GlobalExceptionFilter;
91
- function createExceptionHandler(filter, customFilters = new Map()) {
86
+ export function createExceptionHandler(filter, customFilters = new Map()) {
92
87
  return async (error, request, reply) => {
93
88
  const context = {
94
89
  exception: error,
@@ -1,4 +1,4 @@
1
- import { HttpException, HttpExceptionBody } from './http-exception';
1
+ import { HttpException, HttpExceptionBody } from './http-exception.js';
2
2
  export declare class BadRequestException extends HttpException {
3
3
  constructor(response?: string | HttpExceptionBody);
4
4
  }
@@ -1,112 +1,91 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GatewayTimeoutException = exports.ServiceUnavailableException = exports.BadGatewayException = exports.NotImplementedException = exports.InternalServerErrorException = exports.TooManyRequestsException = exports.UnprocessableEntityException = exports.UnsupportedMediaTypeException = exports.PayloadTooLargeException = exports.GoneException = exports.ConflictException = exports.RequestTimeoutException = exports.NotAcceptableException = exports.MethodNotAllowedException = exports.NotFoundException = exports.ForbiddenException = exports.UnauthorizedException = exports.BadRequestException = void 0;
4
- const http_exception_1 = require("./http-exception");
5
- class BadRequestException extends http_exception_1.HttpException {
1
+ import { HttpException } from './http-exception.js';
2
+ export class BadRequestException extends HttpException {
6
3
  constructor(response = 'Bad Request') {
7
4
  super(response, 400);
8
5
  }
9
6
  }
10
- exports.BadRequestException = BadRequestException;
11
- class UnauthorizedException extends http_exception_1.HttpException {
7
+ export class UnauthorizedException extends HttpException {
12
8
  constructor(response = 'Unauthorized') {
13
9
  super(response, 401);
14
10
  }
15
11
  }
16
- exports.UnauthorizedException = UnauthorizedException;
17
- class ForbiddenException extends http_exception_1.HttpException {
12
+ export class ForbiddenException extends HttpException {
18
13
  constructor(response = 'Forbidden') {
19
14
  super(response, 403);
20
15
  }
21
16
  }
22
- exports.ForbiddenException = ForbiddenException;
23
- class NotFoundException extends http_exception_1.HttpException {
17
+ export class NotFoundException extends HttpException {
24
18
  constructor(response = 'Not Found') {
25
19
  super(response, 404);
26
20
  }
27
21
  }
28
- exports.NotFoundException = NotFoundException;
29
- class MethodNotAllowedException extends http_exception_1.HttpException {
22
+ export class MethodNotAllowedException extends HttpException {
30
23
  constructor(response = 'Method Not Allowed') {
31
24
  super(response, 405);
32
25
  }
33
26
  }
34
- exports.MethodNotAllowedException = MethodNotAllowedException;
35
- class NotAcceptableException extends http_exception_1.HttpException {
27
+ export class NotAcceptableException extends HttpException {
36
28
  constructor(response = 'Not Acceptable') {
37
29
  super(response, 406);
38
30
  }
39
31
  }
40
- exports.NotAcceptableException = NotAcceptableException;
41
- class RequestTimeoutException extends http_exception_1.HttpException {
32
+ export class RequestTimeoutException extends HttpException {
42
33
  constructor(response = 'Request Timeout') {
43
34
  super(response, 408);
44
35
  }
45
36
  }
46
- exports.RequestTimeoutException = RequestTimeoutException;
47
- class ConflictException extends http_exception_1.HttpException {
37
+ export class ConflictException extends HttpException {
48
38
  constructor(response = 'Conflict') {
49
39
  super(response, 409);
50
40
  }
51
41
  }
52
- exports.ConflictException = ConflictException;
53
- class GoneException extends http_exception_1.HttpException {
42
+ export class GoneException extends HttpException {
54
43
  constructor(response = 'Gone') {
55
44
  super(response, 410);
56
45
  }
57
46
  }
58
- exports.GoneException = GoneException;
59
- class PayloadTooLargeException extends http_exception_1.HttpException {
47
+ export class PayloadTooLargeException extends HttpException {
60
48
  constructor(response = 'Payload Too Large') {
61
49
  super(response, 413);
62
50
  }
63
51
  }
64
- exports.PayloadTooLargeException = PayloadTooLargeException;
65
- class UnsupportedMediaTypeException extends http_exception_1.HttpException {
52
+ export class UnsupportedMediaTypeException extends HttpException {
66
53
  constructor(response = 'Unsupported Media Type') {
67
54
  super(response, 415);
68
55
  }
69
56
  }
70
- exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException;
71
- class UnprocessableEntityException extends http_exception_1.HttpException {
57
+ export class UnprocessableEntityException extends HttpException {
72
58
  constructor(response = 'Unprocessable Entity') {
73
59
  super(response, 422);
74
60
  }
75
61
  }
76
- exports.UnprocessableEntityException = UnprocessableEntityException;
77
- class TooManyRequestsException extends http_exception_1.HttpException {
62
+ export class TooManyRequestsException extends HttpException {
78
63
  constructor(response = 'Too Many Requests') {
79
64
  super(response, 429);
80
65
  }
81
66
  }
82
- exports.TooManyRequestsException = TooManyRequestsException;
83
- class InternalServerErrorException extends http_exception_1.HttpException {
67
+ export class InternalServerErrorException extends HttpException {
84
68
  constructor(response = 'Internal Server Error') {
85
69
  super(response, 500);
86
70
  }
87
71
  }
88
- exports.InternalServerErrorException = InternalServerErrorException;
89
- class NotImplementedException extends http_exception_1.HttpException {
72
+ export class NotImplementedException extends HttpException {
90
73
  constructor(response = 'Not Implemented') {
91
74
  super(response, 501);
92
75
  }
93
76
  }
94
- exports.NotImplementedException = NotImplementedException;
95
- class BadGatewayException extends http_exception_1.HttpException {
77
+ export class BadGatewayException extends HttpException {
96
78
  constructor(response = 'Bad Gateway') {
97
79
  super(response, 502);
98
80
  }
99
81
  }
100
- exports.BadGatewayException = BadGatewayException;
101
- class ServiceUnavailableException extends http_exception_1.HttpException {
82
+ export class ServiceUnavailableException extends HttpException {
102
83
  constructor(response = 'Service Unavailable') {
103
84
  super(response, 503);
104
85
  }
105
86
  }
106
- exports.ServiceUnavailableException = ServiceUnavailableException;
107
- class GatewayTimeoutException extends http_exception_1.HttpException {
87
+ export class GatewayTimeoutException extends HttpException {
108
88
  constructor(response = 'Gateway Timeout') {
109
89
  super(response, 504);
110
90
  }
111
91
  }
112
- exports.GatewayTimeoutException = GatewayTimeoutException;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpException = void 0;
4
- class HttpException extends Error {
1
+ export class HttpException extends Error {
5
2
  statusCode;
6
3
  response;
7
4
  timestamp;
@@ -63,4 +60,3 @@ class HttpException extends Error {
63
60
  return errors[statusCode] ?? 'Error';
64
61
  }
65
62
  }
66
- exports.HttpException = HttpException;