@riktajs/core 0.1.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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +205 -0
  3. package/dist/core/application.d.ts +28 -0
  4. package/dist/core/application.d.ts.map +1 -0
  5. package/dist/core/application.js +321 -0
  6. package/dist/core/application.js.map +1 -0
  7. package/dist/core/constants.d.ts +70 -0
  8. package/dist/core/constants.d.ts.map +1 -0
  9. package/dist/core/constants.js +77 -0
  10. package/dist/core/constants.js.map +1 -0
  11. package/dist/core/container/container.d.ts +101 -0
  12. package/dist/core/container/container.d.ts.map +1 -0
  13. package/dist/core/container/container.js +327 -0
  14. package/dist/core/container/container.js.map +1 -0
  15. package/dist/core/container/index.d.ts +3 -0
  16. package/dist/core/container/index.d.ts.map +1 -0
  17. package/dist/core/container/index.js +19 -0
  18. package/dist/core/container/index.js.map +1 -0
  19. package/dist/core/container/injection-token.d.ts +58 -0
  20. package/dist/core/container/injection-token.d.ts.map +1 -0
  21. package/dist/core/container/injection-token.js +37 -0
  22. package/dist/core/container/injection-token.js.map +1 -0
  23. package/dist/core/decorators/autowired.decorator.d.ts +72 -0
  24. package/dist/core/decorators/autowired.decorator.d.ts.map +1 -0
  25. package/dist/core/decorators/autowired.decorator.js +143 -0
  26. package/dist/core/decorators/autowired.decorator.js.map +1 -0
  27. package/dist/core/decorators/controller.decorator.d.ts +33 -0
  28. package/dist/core/decorators/controller.decorator.d.ts.map +1 -0
  29. package/dist/core/decorators/controller.decorator.js +50 -0
  30. package/dist/core/decorators/controller.decorator.js.map +1 -0
  31. package/dist/core/decorators/index.d.ts +7 -0
  32. package/dist/core/decorators/index.d.ts.map +1 -0
  33. package/dist/core/decorators/index.js +24 -0
  34. package/dist/core/decorators/index.js.map +1 -0
  35. package/dist/core/decorators/injectable.decorator.d.ts +26 -0
  36. package/dist/core/decorators/injectable.decorator.d.ts.map +1 -0
  37. package/dist/core/decorators/injectable.decorator.js +40 -0
  38. package/dist/core/decorators/injectable.decorator.js.map +1 -0
  39. package/dist/core/decorators/param.decorator.d.ts +72 -0
  40. package/dist/core/decorators/param.decorator.d.ts.map +1 -0
  41. package/dist/core/decorators/param.decorator.js +88 -0
  42. package/dist/core/decorators/param.decorator.js.map +1 -0
  43. package/dist/core/decorators/provider.decorator.d.ts +64 -0
  44. package/dist/core/decorators/provider.decorator.d.ts.map +1 -0
  45. package/dist/core/decorators/provider.decorator.js +69 -0
  46. package/dist/core/decorators/provider.decorator.js.map +1 -0
  47. package/dist/core/decorators/route.decorator.d.ts +53 -0
  48. package/dist/core/decorators/route.decorator.d.ts.map +1 -0
  49. package/dist/core/decorators/route.decorator.js +85 -0
  50. package/dist/core/decorators/route.decorator.js.map +1 -0
  51. package/dist/core/discovery.d.ts +24 -0
  52. package/dist/core/discovery.d.ts.map +1 -0
  53. package/dist/core/discovery.js +168 -0
  54. package/dist/core/discovery.js.map +1 -0
  55. package/dist/core/exceptions/catch.decorator.d.ts +71 -0
  56. package/dist/core/exceptions/catch.decorator.d.ts.map +1 -0
  57. package/dist/core/exceptions/catch.decorator.js +77 -0
  58. package/dist/core/exceptions/catch.decorator.js.map +1 -0
  59. package/dist/core/exceptions/exception-filter.d.ts +134 -0
  60. package/dist/core/exceptions/exception-filter.d.ts.map +1 -0
  61. package/dist/core/exceptions/exception-filter.js +161 -0
  62. package/dist/core/exceptions/exception-filter.js.map +1 -0
  63. package/dist/core/exceptions/exceptions.d.ts +212 -0
  64. package/dist/core/exceptions/exceptions.d.ts.map +1 -0
  65. package/dist/core/exceptions/exceptions.js +275 -0
  66. package/dist/core/exceptions/exceptions.js.map +1 -0
  67. package/dist/core/exceptions/http-exception.d.ts +79 -0
  68. package/dist/core/exceptions/http-exception.d.ts.map +1 -0
  69. package/dist/core/exceptions/http-exception.js +106 -0
  70. package/dist/core/exceptions/http-exception.js.map +1 -0
  71. package/dist/core/exceptions/index.d.ts +5 -0
  72. package/dist/core/exceptions/index.d.ts.map +1 -0
  73. package/dist/core/exceptions/index.js +38 -0
  74. package/dist/core/exceptions/index.js.map +1 -0
  75. package/dist/core/index.d.ts +11 -0
  76. package/dist/core/index.d.ts.map +1 -0
  77. package/dist/core/index.js +28 -0
  78. package/dist/core/index.js.map +1 -0
  79. package/dist/core/lifecycle/event-bus.d.ts +96 -0
  80. package/dist/core/lifecycle/event-bus.d.ts.map +1 -0
  81. package/dist/core/lifecycle/event-bus.js +91 -0
  82. package/dist/core/lifecycle/event-bus.js.map +1 -0
  83. package/dist/core/lifecycle/index.d.ts +4 -0
  84. package/dist/core/lifecycle/index.d.ts.map +1 -0
  85. package/dist/core/lifecycle/index.js +21 -0
  86. package/dist/core/lifecycle/index.js.map +1 -0
  87. package/dist/core/lifecycle/interfaces.d.ts +106 -0
  88. package/dist/core/lifecycle/interfaces.d.ts.map +1 -0
  89. package/dist/core/lifecycle/interfaces.js +10 -0
  90. package/dist/core/lifecycle/interfaces.js.map +1 -0
  91. package/dist/core/lifecycle/on.decorator.d.ts +62 -0
  92. package/dist/core/lifecycle/on.decorator.d.ts.map +1 -0
  93. package/dist/core/lifecycle/on.decorator.js +65 -0
  94. package/dist/core/lifecycle/on.decorator.js.map +1 -0
  95. package/dist/core/registry.d.ts +64 -0
  96. package/dist/core/registry.d.ts.map +1 -0
  97. package/dist/core/registry.js +91 -0
  98. package/dist/core/registry.js.map +1 -0
  99. package/dist/core/router/router.d.ts +39 -0
  100. package/dist/core/router/router.d.ts.map +1 -0
  101. package/dist/core/router/router.js +150 -0
  102. package/dist/core/router/router.js.map +1 -0
  103. package/dist/core/types.d.ts +161 -0
  104. package/dist/core/types.d.ts.map +1 -0
  105. package/dist/core/types.js +3 -0
  106. package/dist/core/types.js.map +1 -0
  107. package/dist/index.d.ts +44 -0
  108. package/dist/index.d.ts.map +1 -0
  109. package/dist/index.js +64 -0
  110. package/dist/index.js.map +1 -0
  111. package/package.json +47 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/provider.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAGrD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,CASrD"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Provider = Provider;
4
+ require("reflect-metadata");
5
+ const constants_1 = require("../constants");
6
+ const registry_1 = require("../registry");
7
+ /**
8
+ * @Provider() decorator
9
+ *
10
+ * Marks a class as a custom provider that will be auto-discovered.
11
+ * The class must implement a `provide()` method that returns the value.
12
+ *
13
+ * Providers can inject dependencies via constructor or @Autowired properties,
14
+ * making them perfect for complex factory logic.
15
+ *
16
+ * @param token - The injection token this provider supplies
17
+ *
18
+ * @example Simple value provider:
19
+ * ```typescript
20
+ * const APP_CONFIG = new InjectionToken<AppConfig>('app.config');
21
+ *
22
+ * @Provider(APP_CONFIG)
23
+ * export class AppConfigProvider {
24
+ * provide(): AppConfig {
25
+ * return {
26
+ * name: 'My App',
27
+ * version: '1.0.0',
28
+ * };
29
+ * }
30
+ * }
31
+ * ```
32
+ *
33
+ * @example Provider with dependencies:
34
+ * ```typescript
35
+ * const LOGGER = new InjectionToken<Logger>('logger');
36
+ *
37
+ * @Provider(LOGGER)
38
+ * export class LoggerProvider {
39
+ * constructor(@Autowired(APP_CONFIG) private config: AppConfig) {}
40
+ *
41
+ * provide(): Logger {
42
+ * return createLogger({
43
+ * appName: this.config.name,
44
+ * level: this.config.debug ? 'debug' : 'info',
45
+ * });
46
+ * }
47
+ * }
48
+ * ```
49
+ *
50
+ * @example Async provider:
51
+ * ```typescript
52
+ * @Provider(DATABASE)
53
+ * export class DatabaseProvider {
54
+ * async provide(): Promise<Database> {
55
+ * const db = await connectToDatabase();
56
+ * return db;
57
+ * }
58
+ * }
59
+ * ```
60
+ */
61
+ function Provider(token) {
62
+ return (target) => {
63
+ const metadata = { token };
64
+ Reflect.defineMetadata(constants_1.PROVIDER_METADATA, metadata, target);
65
+ // Register in global registry for auto-discovery
66
+ registry_1.registry.registerCustomProvider(target);
67
+ };
68
+ }
69
+ //# sourceMappingURL=provider.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/provider.decorator.ts"],"names":[],"mappings":";;AAkEA,4BASC;AA3ED,4BAA0B;AAC1B,4CAAiD;AAEjD,0CAAuC;AASvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,SAAgB,QAAQ,CAAC,KAAY;IACnC,OAAO,CAAC,MAAgB,EAAE,EAAE;QAC1B,MAAM,QAAQ,GAAqB,EAAE,KAAK,EAAE,CAAC;QAE7C,OAAO,CAAC,cAAc,CAAC,6BAAiB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE5D,iDAAiD;QACjD,mBAAQ,CAAC,sBAAsB,CAAC,MAA6C,CAAC,CAAC;IACjF,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,53 @@
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
+ 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
+ export declare const Post: (path?: string) => MethodDecorator;
22
+ /**
23
+ * @Put() decorator - Handles HTTP PUT requests
24
+ */
25
+ export declare const Put: (path?: string) => MethodDecorator;
26
+ /**
27
+ * @Patch() decorator - Handles HTTP PATCH requests
28
+ */
29
+ export declare const Patch: (path?: string) => MethodDecorator;
30
+ /**
31
+ * @Delete() decorator - Handles HTTP DELETE requests
32
+ */
33
+ export declare const Delete: (path?: string) => MethodDecorator;
34
+ /**
35
+ * @Options() decorator - Handles HTTP OPTIONS requests
36
+ */
37
+ export declare const Options: (path?: string) => MethodDecorator;
38
+ /**
39
+ * @Head() decorator - Handles HTTP HEAD requests
40
+ */
41
+ 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
+ export declare function HttpCode(statusCode: number): MethodDecorator;
53
+ //# sourceMappingURL=route.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/route.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAgC1B;;;;;;;;GAQG;AACH,eAAO,MAAM,GAAG,UAjCA,MAAM,KAAQ,eAiCgB,CAAC;AAE/C;;;;;;;;GAQG;AACH,eAAO,MAAM,IAAI,UA5CD,MAAM,KAAQ,eA4CkB,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,GAAG,UAjDA,MAAM,KAAQ,eAiDgB,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,KAAK,UAtDF,MAAM,KAAQ,eAsDoB,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,MAAM,UA3DH,MAAM,KAAQ,eA2DsB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,OAAO,UAhEJ,MAAM,KAAQ,eAgEwB,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,IAAI,UArED,MAAM,KAAQ,eAqEkB,CAAC;AAEjD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,CAK5D"}
@@ -0,0 +1,85 @@
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");
7
+ /**
8
+ * Creates a route decorator for a specific HTTP method
9
+ */
10
+ function createRouteDecorator(method) {
11
+ return (path = '') => {
12
+ return (target, propertyKey, descriptor) => {
13
+ // Normalize path
14
+ const normalizedPath = path.startsWith('/') ? path : `/${path}`;
15
+ // Get existing routes or initialize empty array
16
+ const routes = Reflect.getMetadata(constants_1.ROUTES_METADATA, target.constructor) ?? [];
17
+ // Add this route
18
+ routes.push({
19
+ method,
20
+ path: normalizedPath === '/' ? '' : normalizedPath,
21
+ handlerName: propertyKey,
22
+ });
23
+ // Store updated routes
24
+ Reflect.defineMetadata(constants_1.ROUTES_METADATA, routes, target.constructor);
25
+ return descriptor;
26
+ };
27
+ };
28
+ }
29
+ /**
30
+ * @Get() decorator - Handles HTTP GET requests
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * @Get('/users')
35
+ * getUsers() { return []; }
36
+ * ```
37
+ */
38
+ 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
+ exports.Post = createRouteDecorator('POST');
49
+ /**
50
+ * @Put() decorator - Handles HTTP PUT requests
51
+ */
52
+ exports.Put = createRouteDecorator('PUT');
53
+ /**
54
+ * @Patch() decorator - Handles HTTP PATCH requests
55
+ */
56
+ exports.Patch = createRouteDecorator('PATCH');
57
+ /**
58
+ * @Delete() decorator - Handles HTTP DELETE requests
59
+ */
60
+ exports.Delete = createRouteDecorator('DELETE');
61
+ /**
62
+ * @Options() decorator - Handles HTTP OPTIONS requests
63
+ */
64
+ exports.Options = createRouteDecorator('OPTIONS');
65
+ /**
66
+ * @Head() decorator - Handles HTTP HEAD requests
67
+ */
68
+ 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
+ function HttpCode(statusCode) {
80
+ return (target, propertyKey, descriptor) => {
81
+ Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA, statusCode, target.constructor, propertyKey);
82
+ return descriptor;
83
+ };
84
+ }
85
+ //# sourceMappingURL=route.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/route.decorator.ts"],"names":[],"mappings":";;;AAyFA,4BAKC;AA9FD,4BAA0B;AAC1B,4CAAmE;AAGnE;;GAEG;AACH,SAAS,oBAAoB,CAAC,MAAkB;IAC9C,OAAO,CAAC,OAAe,EAAE,EAAmB,EAAE;QAC5C,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,UAA8B,EAAE,EAAE;YACtF,iBAAiB;YACjB,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;YAEhE,gDAAgD;YAChD,MAAM,MAAM,GACV,OAAO,CAAC,WAAW,CAAC,2BAAe,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAEjE,iBAAiB;YACjB,MAAM,CAAC,IAAI,CAAC;gBACV,MAAM;gBACN,IAAI,EAAE,cAAc,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc;gBAClD,WAAW,EAAE,WAAW;aACzB,CAAC,CAAC;YAEH,uBAAuB;YACvB,OAAO,CAAC,cAAc,CAAC,2BAAe,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;YAEpE,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACU,QAAA,GAAG,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAE/C;;;;;;;;GAQG;AACU,QAAA,IAAI,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAEjD;;GAEG;AACU,QAAA,GAAG,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAE/C;;GAEG;AACU,QAAA,KAAK,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAEnD;;GAEG;AACU,QAAA,MAAM,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AAErD;;GAEG;AACU,QAAA,OAAO,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;AAEvD;;GAEG;AACU,QAAA,IAAI,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAEjD;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,UAAkB;IACzC,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,UAA8B,EAAE,EAAE;QACtF,OAAO,CAAC,cAAc,CAAC,8BAAkB,EAAE,UAAU,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QACxF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,24 @@
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 to search for files (default: ['./**'])
7
+ * @param cwd - Base directory for pattern matching (default: process.cwd())
8
+ * @returns Promise resolving to list of imported files
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Scan specific directories
13
+ * await discoverModules(['./src/controllers', './src/services']);
14
+ *
15
+ * // Scan everything (default)
16
+ * await discoverModules();
17
+ * ```
18
+ */
19
+ export declare function discoverModules(patterns?: string[], cwd?: string): Promise<string[]>;
20
+ /**
21
+ * Get the caller's directory (useful for relative pattern resolution)
22
+ */
23
+ export declare function getCallerDirectory(): string;
24
+ //# sourceMappingURL=discovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":"AAqCA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,eAAe,CACnC,QAAQ,GAAE,MAAM,EAAuB,EACvC,GAAG,GAAE,MAAsB,GAC1B,OAAO,CAAC,MAAM,EAAE,CAAC,CAgDnB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CA+B3C"}
@@ -0,0 +1,168 @@
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"));
44
+ /**
45
+ * Default patterns to exclude from discovery
46
+ */
47
+ const DEFAULT_IGNORE_PATTERNS = [
48
+ '**/node_modules/**',
49
+ '**/dist/**',
50
+ '**/build/**',
51
+ '**/*.test.ts',
52
+ '**/*.spec.ts',
53
+ '**/*.d.ts',
54
+ ];
55
+ /**
56
+ * Regex patterns to detect Rikta decorators
57
+ */
58
+ const DECORATOR_PATTERNS = [
59
+ /@Controller\s*\(/, // @Controller() or @Controller('/path')
60
+ /@Injectable\s*\(/, // @Injectable() or @Injectable({ scope: 'singleton' })
61
+ /@Provider\s*\(/, // @Provider(TOKEN)
62
+ ];
63
+ /**
64
+ * Check if a file contains Rikta decorators (@Controller, @Injectable, or @Provider)
65
+ */
66
+ async function containsRiktaDecorators(filePath) {
67
+ try {
68
+ const content = await promises_1.default.readFile(filePath, 'utf-8');
69
+ return DECORATOR_PATTERNS.some(pattern => pattern.test(content));
70
+ }
71
+ catch {
72
+ return false;
73
+ }
74
+ }
75
+ /**
76
+ * Discover and import modules matching the given patterns
77
+ *
78
+ * Only imports files that contain @Controller, @Injectable, or @Provider decorators.
79
+ *
80
+ * @param patterns - Glob patterns to search for files (default: ['./**'])
81
+ * @param cwd - Base directory for pattern matching (default: process.cwd())
82
+ * @returns Promise resolving to list of imported files
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * // Scan specific directories
87
+ * await discoverModules(['./src/controllers', './src/services']);
88
+ *
89
+ * // Scan everything (default)
90
+ * await discoverModules();
91
+ * ```
92
+ */
93
+ async function discoverModules(patterns = ['./**/*.{ts,js}'], cwd = process.cwd()) {
94
+ // Normalize patterns to include file extensions if not present
95
+ const normalizedPatterns = patterns.map(pattern => {
96
+ // If pattern already has extension, use as-is
97
+ if (/\.\w+$/.test(pattern) || pattern.endsWith('*')) {
98
+ return pattern;
99
+ }
100
+ // Add file extension pattern
101
+ return pattern.endsWith('/')
102
+ ? `${pattern}**/*.{ts,js}`
103
+ : `${pattern}/**/*.{ts,js}`;
104
+ });
105
+ // Find all matching files
106
+ const files = await (0, fast_glob_1.default)(normalizedPatterns, {
107
+ cwd,
108
+ absolute: true,
109
+ ignore: DEFAULT_IGNORE_PATTERNS,
110
+ onlyFiles: true,
111
+ });
112
+ // Filter files that contain Rikta decorators
113
+ const riktaFiles = [];
114
+ for (const file of files) {
115
+ if (await containsRiktaDecorators(file)) {
116
+ riktaFiles.push(file);
117
+ }
118
+ }
119
+ // Import only files with decorators
120
+ const importedFiles = [];
121
+ for (const file of riktaFiles) {
122
+ try {
123
+ // Convert to proper import path
124
+ const importPath = file.replace(/\.ts$/, '');
125
+ await Promise.resolve(`${importPath}`).then(s => __importStar(require(s)));
126
+ importedFiles.push(file);
127
+ }
128
+ catch (error) {
129
+ // Log but don't fail - some files might have import errors
130
+ if (process.env.DEBUG) {
131
+ console.warn(`[Rikta] Failed to import ${file}:`, error);
132
+ }
133
+ }
134
+ }
135
+ return importedFiles;
136
+ }
137
+ /**
138
+ * Get the caller's directory (useful for relative pattern resolution)
139
+ */
140
+ function getCallerDirectory() {
141
+ const originalPrepareStackTrace = Error.prepareStackTrace;
142
+ try {
143
+ const err = new Error();
144
+ let callerFile;
145
+ Error.prepareStackTrace = (_, stack) => stack;
146
+ const stack = err.stack;
147
+ // Find the first file that's not this module
148
+ for (const site of stack) {
149
+ const filename = site.getFileName();
150
+ if (filename && !filename.includes('discovery.ts') && !filename.includes('application.ts')) {
151
+ callerFile = filename;
152
+ break;
153
+ }
154
+ }
155
+ if (callerFile) {
156
+ // Handle file:// URLs (ESM) and regular paths
157
+ const filePath = callerFile.startsWith('file://')
158
+ ? new URL(callerFile).pathname
159
+ : callerFile;
160
+ return path_1.default.dirname(filePath);
161
+ }
162
+ return process.cwd();
163
+ }
164
+ finally {
165
+ Error.prepareStackTrace = originalPrepareStackTrace;
166
+ }
167
+ }
168
+ //# sourceMappingURL=discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,0CAmDC;AAKD,gDA+BC;AA9ID,0DAA2B;AAC3B,2DAA6B;AAC7B,gDAAwB;AAExB;;GAEG;AACH,MAAM,uBAAuB,GAAG;IAC9B,oBAAoB;IACpB,YAAY;IACZ,aAAa;IACb,cAAc;IACd,cAAc;IACd,WAAW;CACZ,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAAG;IACzB,kBAAkB,EAAK,wCAAwC;IAC/D,kBAAkB,EAAK,uDAAuD;IAC9E,gBAAgB,EAAO,mBAAmB;CAC3C,CAAC;AAEF;;GAEG;AACH,KAAK,UAAU,uBAAuB,CAAC,QAAgB;IACrD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACI,K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AyB,CAAC;IACtD,CAAC;AACH,CAAC"}
@@ -0,0 +1,71 @@
1
+ import 'reflect-metadata';
2
+ import { Constructor } from '../types';
3
+ /**
4
+ * Metadata key for @Catch() decorator
5
+ */
6
+ export declare const CATCH_METADATA: unique symbol;
7
+ /**
8
+ * Metadata stored by @Catch() decorator
9
+ */
10
+ export interface CatchMetadata {
11
+ /** Exception types this filter handles */
12
+ exceptions: Constructor<Error>[];
13
+ }
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
+ export declare function Catch(...exceptions: Constructor<Error>[]): ClassDecorator;
67
+ /**
68
+ * Get catch metadata from a filter class
69
+ */
70
+ export declare function getCatchMetadata(target: Constructor): CatchMetadata | undefined;
71
+ //# sourceMappingURL=catch.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catch.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/exceptions/catch.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,cAAc,eAA2B,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,0CAA0C;IAC1C,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,KAAK,CAAC,GAAG,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,GAAG,cAAc,CAQzE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,aAAa,GAAG,SAAS,CAE/E"}
@@ -0,0 +1,77 @@
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
+ /**
8
+ * Metadata key for @Catch() decorator
9
+ */
10
+ 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
+ function Catch(...exceptions) {
64
+ return (target) => {
65
+ const metadata = {
66
+ exceptions: exceptions.length > 0 ? exceptions : [],
67
+ };
68
+ Reflect.defineMetadata(exports.CATCH_METADATA, metadata, target);
69
+ };
70
+ }
71
+ /**
72
+ * Get catch metadata from a filter class
73
+ */
74
+ function getCatchMetadata(target) {
75
+ return Reflect.getMetadata(exports.CATCH_METADATA, target);
76
+ }
77
+ //# sourceMappingURL=catch.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catch.decorator.js","sourceRoot":"","sources":["../../../src/core/exceptions/catch.decorator.ts"],"names":[],"mappings":";;;AAoEA,sBAQC;AAKD,4CAEC;AAnFD,4BAA0B;AAG1B;;GAEG;AACU,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAUvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,SAAgB,KAAK,CAAC,GAAG,UAAgC;IACvD,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,MAAM,QAAQ,GAAkB;YAC9B,UAAU,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;SACpD,CAAC;QAEF,OAAO,CAAC,cAAc,CAAC,sBAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,MAAmB;IAClD,OAAO,OAAO,CAAC,WAAW,CAAC,sBAAc,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC"}