@riktajs/core 0.4.4 → 0.4.6

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 +0 -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 -1
  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
@@ -2,25 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Registry = exports.registry = void 0;
4
4
  const config_exceptions_1 = require("./exceptions/config.exceptions");
5
- /**
6
- * Global Registry
7
- *
8
- * Stores references to all decorated classes for auto-discovery.
9
- * Controllers and providers register themselves here via decorators.
10
- *
11
- * The registry acts as a collection point during the decoration phase.
12
- * Once the application initializes, the registered classes are processed
13
- * and transferred to the DI container for resolution.
14
- */
15
5
  class Registry {
16
6
  static instance;
17
- /** All registered controllers */
18
7
  controllers = new Set();
19
- /** All registered providers (services via @Injectable) */
20
8
  providers = new Set();
21
- /** All registered custom providers (via @Provider) */
22
9
  customProviders = new Set();
23
- /** Map of config provider tokens to their class constructors */
24
10
  configProviderMap = new Map();
25
11
  constructor() { }
26
12
  static getInstance() {
@@ -29,82 +15,37 @@ class Registry {
29
15
  }
30
16
  return Registry.instance;
31
17
  }
32
- /**
33
- * Reset the registry (useful for testing)
34
- */
35
18
  static reset() {
36
19
  const newInstance = new Registry();
37
20
  Registry.instance = newInstance;
38
21
  }
39
- /**
40
- * Register a controller
41
- */
42
22
  registerController(target) {
43
23
  this.controllers.add(target);
44
24
  }
45
- /**
46
- * Register a provider
47
- */
48
25
  registerProvider(target) {
49
26
  this.providers.add(target);
50
27
  }
51
- /**
52
- * Get all registered controllers
53
- */
54
28
  getControllers() {
55
29
  return [...this.controllers];
56
30
  }
57
- /**
58
- * Get all registered providers
59
- */
60
31
  getProviders() {
61
32
  return [...this.providers];
62
33
  }
63
- /**
64
- * Check if a controller is registered
65
- */
66
34
  hasController(target) {
67
35
  return this.controllers.has(target);
68
36
  }
69
- /**
70
- * Check if a provider is registered
71
- */
72
37
  hasProvider(target) {
73
38
  return this.providers.has(target);
74
39
  }
75
- /**
76
- * Register a custom provider (@Provider)
77
- */
78
40
  registerCustomProvider(target) {
79
41
  this.customProviders.add(target);
80
42
  }
81
- /**
82
- * Get all registered custom providers
83
- */
84
43
  getCustomProviders() {
85
44
  return [...this.customProviders];
86
45
  }
87
- /**
88
- * Check if a custom provider is registered
89
- */
90
46
  hasCustomProvider(target) {
91
47
  return this.customProviders.has(target);
92
48
  }
93
- // ============================================================================
94
- // Config Provider Methods
95
- // ============================================================================
96
- /**
97
- * Register a config provider with its injection token
98
- *
99
- * @param token - The injection token (e.g., 'APP_CONFIG')
100
- * @param providerClass - The config provider class constructor
101
- * @throws {ConfigProviderAlreadyRegisteredException} If the token is already registered
102
- *
103
- * @example
104
- * ```typescript
105
- * registry.registerConfigProvider('APP_CONFIG', AppConfigProvider);
106
- * ```
107
- */
108
49
  registerConfigProvider(token, providerClass) {
109
50
  if (this.configProviderMap.has(token)) {
110
51
  const existingClass = this.configProviderMap.get(token);
@@ -112,33 +53,15 @@ class Registry {
112
53
  }
113
54
  this.configProviderMap.set(token, providerClass);
114
55
  }
115
- /**
116
- * Get all registered config provider classes with their tokens
117
- *
118
- * @returns Array of registration info objects
119
- *
120
- * @internal Used by auto-discovery mechanism
121
- */
122
56
  getConfigProviderRegistrations() {
123
57
  return Array.from(this.configProviderMap.entries()).map(([token, providerClass]) => ({
124
58
  token,
125
59
  providerClass,
126
60
  }));
127
61
  }
128
- /**
129
- * Clear all config provider registrations (useful for testing)
130
- *
131
- * This will remove all registered config providers
132
- *
133
- * @internal
134
- */
135
62
  clearConfigProviders() {
136
63
  this.configProviderMap.clear();
137
64
  }
138
65
  }
139
66
  exports.Registry = Registry;
140
- /**
141
- * Global registry instance
142
- */
143
67
  exports.registry = Registry.getInstance();
144
- //# sourceMappingURL=registry.js.map
@@ -2,59 +2,18 @@ import 'reflect-metadata';
2
2
  import { FastifyInstance } from 'fastify';
3
3
  import { Container } from '../container/container';
4
4
  import { Constructor } from '../types';
5
- /**
6
- * Router class
7
- *
8
- * Responsible for:
9
- * - Scanning controllers for route metadata
10
- * - Registering routes with Fastify
11
- * - Handling parameter injection
12
- *
13
- * Performance optimizations:
14
- * - Pre-compiled parameter extractors
15
- * - Guard instance caching
16
- * - Fast path for simple routes
17
- */
18
5
  export declare class Router {
19
6
  private readonly server;
20
7
  private readonly container;
21
8
  private readonly globalPrefix;
22
- /** Cache for guard instances (singleton per guard class) */
23
9
  private readonly guardCache;
24
10
  constructor(server: FastifyInstance, container: Container, globalPrefix?: string);
25
- /**
26
- * Register all routes from a controller
27
- */
28
11
  registerController(controllerClass: Constructor, silent?: boolean): void;
29
- /**
30
- * Register a single route
31
- */
32
12
  private registerRoute;
33
- /**
34
- * OPTIMIZATION: Compile parameter resolvers at route registration time
35
- * Each resolver is a pre-built extractor function
36
- */
37
13
  private compileParamResolvers;
38
- /**
39
- * OPTIMIZATION: Create a specialized extractor function for each param type
40
- * This avoids switch statements at runtime
41
- */
42
14
  private createParamExtractor;
43
- /**
44
- * OPTIMIZATION: Resolve params using pre-compiled extractors
45
- */
46
15
  private resolveParamsOptimized;
47
- /**
48
- * OPTIMIZATION: Pre-resolve guard instances at route registration
49
- */
50
16
  private resolveGuardInstances;
51
- /**
52
- * OPTIMIZATION: Execute guards using pre-resolved instances
53
- */
54
17
  private executeGuardsOptimized;
55
- /**
56
- * Build the full route path
57
- */
58
18
  private buildPath;
59
19
  }
60
- //# sourceMappingURL=router.d.ts.map
@@ -7,89 +7,49 @@ const validation_exception_1 = require("../exceptions/validation.exception");
7
7
  const exceptions_1 = require("../exceptions/exceptions");
8
8
  const execution_context_1 = require("../guards/execution-context");
9
9
  const use_guards_decorator_1 = require("../guards/use-guards.decorator");
10
- /**
11
- * Router class
12
- *
13
- * Responsible for:
14
- * - Scanning controllers for route metadata
15
- * - Registering routes with Fastify
16
- * - Handling parameter injection
17
- *
18
- * Performance optimizations:
19
- * - Pre-compiled parameter extractors
20
- * - Guard instance caching
21
- * - Fast path for simple routes
22
- */
23
10
  class Router {
24
11
  server;
25
12
  container;
26
13
  globalPrefix;
27
- /** Cache for guard instances (singleton per guard class) */
28
14
  guardCache = new Map();
29
15
  constructor(server, container, globalPrefix = '') {
30
16
  this.server = server;
31
17
  this.container = container;
32
18
  this.globalPrefix = globalPrefix;
33
19
  }
34
- /**
35
- * Register all routes from a controller
36
- */
37
20
  registerController(controllerClass, silent = false) {
38
- // Get controller metadata
39
21
  const controllerMeta = Reflect.getMetadata(constants_1.CONTROLLER_METADATA, controllerClass);
40
22
  if (!controllerMeta) {
41
23
  throw new Error(`${controllerClass.name} is not decorated with @Controller(). ` +
42
24
  `Make sure to add the decorator.`);
43
25
  }
44
- // Resolve controller instance from container
45
26
  const controllerInstance = this.container.resolve(controllerClass);
46
- // Get routes metadata
47
27
  const routes = Reflect.getMetadata(constants_1.ROUTES_METADATA, controllerClass) ?? [];
48
- // Register each route
49
28
  for (const route of routes) {
50
29
  this.registerRoute(controllerClass, controllerInstance, controllerMeta.prefix, route, silent);
51
30
  }
52
31
  }
53
- /**
54
- * Register a single route
55
- */
56
32
  registerRoute(controllerClass, controllerInstance, controllerPrefix, route, silent = false) {
57
- // Build full path
58
33
  const fullPath = this.buildPath(controllerPrefix, route.path);
59
- // Get the handler method
60
34
  const handler = controllerInstance[route.handlerName];
61
35
  if (typeof handler !== 'function') {
62
36
  throw new Error(`Handler ${String(route.handlerName)} not found on ${controllerClass.name}`);
63
37
  }
64
- // Get parameter metadata
65
38
  const paramsMeta = Reflect.getMetadata(constants_1.PARAM_METADATA, controllerClass, route.handlerName) ?? [];
66
- // Get HTTP status code if set
67
39
  const statusCode = Reflect.getMetadata(constants_1.HTTP_CODE_METADATA, controllerClass, route.handlerName);
68
- // Get guards for this route (controller-level + method-level)
69
40
  const guards = (0, use_guards_decorator_1.getGuardsMetadata)(controllerClass, route.handlerName);
70
- // ============================================
71
- // OPTIMIZATION: Pre-compile parameter resolvers
72
- // ============================================
73
41
  const compiledResolvers = this.compileParamResolvers(paramsMeta);
74
42
  const hasParams = compiledResolvers.length > 0;
75
43
  const maxParamIndex = hasParams ? Math.max(...compiledResolvers.map(r => r.index)) : -1;
76
- // ============================================
77
- // OPTIMIZATION: Pre-resolve guard instances
78
- // ============================================
79
44
  const guardInstances = this.resolveGuardInstances(guards);
80
45
  const hasGuards = guardInstances.length > 0;
81
- // ============================================
82
- // OPTIMIZATION: Create specialized handlers
83
- // ============================================
84
46
  let routeHandler;
85
47
  if (!hasGuards && !hasParams && !statusCode) {
86
- // FAST PATH: No guards, no params, no custom status
87
48
  routeHandler = async (_request, _reply) => {
88
49
  return handler.call(controllerInstance);
89
50
  };
90
51
  }
91
52
  else if (!hasGuards && !hasParams) {
92
- // Fast path: Just status code
93
53
  routeHandler = async (_request, reply) => {
94
54
  const result = await handler.call(controllerInstance);
95
55
  if (statusCode)
@@ -98,7 +58,6 @@ class Router {
98
58
  };
99
59
  }
100
60
  else if (!hasGuards) {
101
- // Medium path: Params but no guards
102
61
  routeHandler = async (request, reply) => {
103
62
  const args = this.resolveParamsOptimized(compiledResolvers, maxParamIndex, request, reply);
104
63
  const result = await handler.apply(controllerInstance, args);
@@ -108,13 +67,9 @@ class Router {
108
67
  };
109
68
  }
110
69
  else {
111
- // Full path: Guards + params
112
- // Pre-create execution context factory for this route
113
70
  const createContext = (req, rep) => new execution_context_1.ExecutionContextImpl(req, rep, controllerClass, route.handlerName);
114
71
  routeHandler = async (request, reply) => {
115
- // Execute guards with cached instances
116
72
  await this.executeGuardsOptimized(guardInstances, createContext(request, reply));
117
- // Resolve params if needed
118
73
  const args = hasParams
119
74
  ? this.resolveParamsOptimized(compiledResolvers, maxParamIndex, request, reply)
120
75
  : [];
@@ -124,17 +79,11 @@ class Router {
124
79
  return result;
125
80
  };
126
81
  }
127
- // Register with Fastify
128
82
  const method = route.method.toLowerCase();
129
83
  this.server[method](fullPath, routeHandler);
130
- // Log route registration
131
84
  if (!silent)
132
85
  console.log(` → ${route.method.padEnd(7)} ${fullPath}`);
133
86
  }
134
- /**
135
- * OPTIMIZATION: Compile parameter resolvers at route registration time
136
- * Each resolver is a pre-built extractor function
137
- */
138
87
  compileParamResolvers(paramsMeta) {
139
88
  if (paramsMeta.length === 0)
140
89
  return [];
@@ -148,10 +97,6 @@ class Router {
148
97
  };
149
98
  });
150
99
  }
151
- /**
152
- * OPTIMIZATION: Create a specialized extractor function for each param type
153
- * This avoids switch statements at runtime
154
- */
155
100
  createParamExtractor(param) {
156
101
  const key = param.key;
157
102
  switch (param.type) {
@@ -182,11 +127,7 @@ class Router {
182
127
  return () => undefined;
183
128
  }
184
129
  }
185
- /**
186
- * OPTIMIZATION: Resolve params using pre-compiled extractors
187
- */
188
130
  resolveParamsOptimized(resolvers, maxIndex, request, reply) {
189
- // Build context once
190
131
  const context = {
191
132
  request,
192
133
  reply,
@@ -194,12 +135,10 @@ class Router {
194
135
  query: request.query,
195
136
  body: request.body,
196
137
  };
197
- // Pre-allocate array
198
138
  const args = new Array(maxIndex + 1);
199
139
  for (let i = 0; i < resolvers.length; i++) {
200
140
  const resolver = resolvers[i];
201
141
  let value = resolver.extract(context);
202
- // Validate if schema present
203
142
  if (resolver.zodSchema) {
204
143
  const result = resolver.zodSchema.safeParse(value);
205
144
  if (!result.success) {
@@ -211,16 +150,11 @@ class Router {
211
150
  }
212
151
  return args;
213
152
  }
214
- /**
215
- * OPTIMIZATION: Pre-resolve guard instances at route registration
216
- */
217
153
  resolveGuardInstances(guards) {
218
154
  return guards.map(GuardClass => {
219
- // Check cache first
220
155
  let instance = this.guardCache.get(GuardClass);
221
156
  if (instance)
222
157
  return instance;
223
- // Resolve from container
224
158
  try {
225
159
  instance = this.container.resolve(GuardClass);
226
160
  }
@@ -229,19 +163,14 @@ class Router {
229
163
  `Make sure it is decorated with @Injectable(). ` +
230
164
  `Original error: ${error instanceof Error ? error.message : String(error)}`);
231
165
  }
232
- // Verify interface
233
166
  if (typeof instance.canActivate !== 'function') {
234
167
  throw new Error(`${GuardClass.name} does not implement CanActivate interface. ` +
235
168
  `The guard must have a canActivate(context: ExecutionContext) method.`);
236
169
  }
237
- // Cache for future use
238
170
  this.guardCache.set(GuardClass, instance);
239
171
  return instance;
240
172
  });
241
173
  }
242
- /**
243
- * OPTIMIZATION: Execute guards using pre-resolved instances
244
- */
245
174
  async executeGuardsOptimized(guardInstances, context) {
246
175
  for (let i = 0; i < guardInstances.length; i++) {
247
176
  const result = await guardInstances[i].canActivate(context);
@@ -250,16 +179,11 @@ class Router {
250
179
  }
251
180
  }
252
181
  }
253
- /**
254
- * Build the full route path
255
- */
256
182
  buildPath(controllerPrefix, routePath) {
257
183
  const parts = [this.globalPrefix, controllerPrefix, routePath]
258
184
  .filter(Boolean)
259
185
  .join('');
260
- // Normalize multiple slashes
261
186
  return parts.replace(/\/+/g, '/') || '/';
262
187
  }
263
188
  }
264
189
  exports.Router = Router;
265
- //# sourceMappingURL=router.js.map
@@ -1,16 +1,7 @@
1
1
  import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
2
2
  import { Container } from "@rikta/core/container";
3
- /**
4
- * Constructor type for class instantiation
5
- */
6
3
  export type Constructor<T = any> = new (...args: any[]) => T;
7
- /**
8
- * HTTP methods supported by the framework
9
- */
10
4
  export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
11
- /**
12
- * Route handler context
13
- */
14
5
  export interface RouteContext {
15
6
  request: FastifyRequest;
16
7
  reply: FastifyReply;
@@ -18,143 +9,44 @@ export interface RouteContext {
18
9
  query: Record<string, unknown>;
19
10
  body: unknown;
20
11
  }
21
- /**
22
- * Route definition metadata
23
- */
24
12
  export interface RouteDefinition {
25
13
  method: HttpMethod;
26
14
  path: string;
27
15
  handlerName: string | symbol;
28
16
  statusCode?: number;
29
17
  }
30
- /**
31
- * Controller metadata
32
- */
33
18
  export interface ControllerMetadata {
34
19
  prefix: string;
35
20
  routes: RouteDefinition[];
36
21
  }
37
- /**
38
- * Provider scope for dependency injection
39
- */
40
22
  export type ProviderScope = 'singleton' | 'transient' | 'request';
41
- /**
42
- * Injectable options
43
- */
44
23
  export interface InjectableOptions {
45
- /** Provider scope (default: 'singleton') */
46
24
  scope?: ProviderScope;
47
- /**
48
- * Initialization priority (higher = initialized first)
49
- * Default: 0
50
- *
51
- * @example
52
- * ```typescript
53
- * @Injectable({ priority: 100 })
54
- * class DatabaseService { } // Initialized first
55
- *
56
- * @Injectable({ priority: 50 })
57
- * class CacheService { } // Initialized second
58
- *
59
- * @Injectable() // priority: 0
60
- * class UserService { } // Initialized last
61
- * ```
62
- */
63
25
  priority?: number;
64
26
  }
65
- /**
66
- * Exception filter options
67
- */
68
27
  export interface ExceptionFilterConfig {
69
- /** Include stack trace in error response (default: true in development) */
70
28
  includeStack?: boolean;
71
- /** Log errors to console (default: true) */
72
29
  logErrors?: boolean;
73
30
  }
74
- /**
75
- * Application configuration
76
- */
77
31
  export interface RiktaConfig {
78
- /** Server port (default: 3000) */
79
32
  port?: number;
80
- /** Server host (default: '0.0.0.0') */
81
33
  host?: string;
82
- /** Enable Fastify logging (default: true) */
83
34
  logger?: boolean | object;
84
- /** Disable all framework console output (default: false) */
85
35
  silent?: boolean;
86
- /** Global route prefix (default: '') */
87
36
  prefix?: string;
88
- /**
89
- * Glob patterns for auto-discovery of controllers and services.
90
- * Files matching these patterns will be imported automatically.
91
- *
92
- * @default ['./**'] (scans current directory recursively)
93
- *
94
- * @example
95
- * ```typescript
96
- * // Scan specific directories
97
- * autowired: ['./src/controllers', './src/services']
98
- *
99
- * // Scan with glob patterns
100
- * autowired: ['./src/**\/*.controller.ts', './src/**\/*.service.ts']
101
- * ```
102
- */
103
37
  autowired?: string[] | false;
104
- /**
105
- * Explicit list of controllers to register.
106
- * If not provided, all @Controller decorated classes are auto-discovered.
107
- */
108
38
  controllers?: Constructor[];
109
- /**
110
- * Additional providers to register.
111
- * Most providers are auto-discovered via @Injectable.
112
- * Use this for custom providers or manual registration.
113
- */
114
39
  providers?: Constructor[];
115
- /**
116
- * Exception filter configuration.
117
- * Controls how errors are handled and formatted.
118
- *
119
- * @example
120
- * ```typescript
121
- * exceptionFilter: {
122
- * includeStack: process.env.NODE_ENV !== 'production',
123
- * logErrors: true
124
- * }
125
- * ```
126
- */
127
40
  exceptionFilter?: ExceptionFilterConfig;
128
- /**
129
- * Custom exception filters.
130
- * Filters are matched against exception types in order.
131
- *
132
- * @example
133
- * ```typescript
134
- * exceptionFilters: [ValidationExceptionFilter, CustomErrorFilter]
135
- * ```
136
- */
137
41
  exceptionFilters?: Constructor[];
138
42
  }
139
- /**
140
- * Middleware function signature
141
- */
142
43
  export type MiddlewareFunction = (request: FastifyRequest, reply: FastifyReply, next: () => Promise<void>) => Promise<void> | void;
143
- /**
144
- * Guard interface for route protection
145
- */
146
44
  export interface Guard {
147
45
  canActivate(context: RouteContext): boolean | Promise<boolean>;
148
46
  }
149
- /**
150
- * Interceptor interface for request/response manipulation
151
- */
152
47
  export interface Interceptor {
153
48
  intercept(context: RouteContext, next: () => Promise<unknown>): Promise<unknown>;
154
49
  }
155
- /**
156
- * Application instance interface
157
- */
158
50
  export interface RiktaApplication {
159
51
  readonly server: FastifyInstance;
160
52
  listen(): Promise<string>;
@@ -162,4 +54,3 @@ export interface RiktaApplication {
162
54
  getUrl(): string;
163
55
  getContainer(): Container;
164
56
  }
165
- //# sourceMappingURL=types.d.ts.map
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
package/dist/index.d.ts CHANGED
@@ -1,44 +1,2 @@
1
- /**
2
- * Rikta Framework
3
- *
4
- * A modern TypeScript backend framework with zero-config autowiring, powered by Fastify.
5
- *
6
- * Features:
7
- * - Decorator-based routing (@Controller, @Get, @Post, etc.)
8
- * - Full Autowiring - No modules needed, everything is auto-discovered
9
- * - Single DI decorator - @Autowired() for constructor and property injection
10
- * - Hybrid Lifecycle - Interface hooks + EventBus
11
- * - Exception Handling - Built-in filters with standardized JSON responses
12
- * - Fastify under the hood for maximum performance
13
- * - Full TypeScript support
14
- *
15
- * @example
16
- * ```typescript
17
- * import { Rikta, Controller, Get, Injectable, Autowired } from '@rikta/core';
18
- *
19
- * @Injectable()
20
- * class GreetingService {
21
- * getGreeting(): string {
22
- * return 'Hello from Rikta!';
23
- * }
24
- * }
25
- *
26
- * @Controller()
27
- * class AppController {
28
- * @Autowired()
29
- * private greetingService!: GreetingService;
30
- *
31
- * @Get('/')
32
- * getHello() {
33
- * return this.greetingService.getGreeting();
34
- * }
35
- * }
36
- *
37
- * // No modules - just create and run!
38
- * const app = await Rikta.create({ port: 3000 });
39
- * await app.listen();
40
- * ```
41
- */
42
1
  export * from './core';
43
2
  export { RiktaFactory as default } from './core/application';
44
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,45 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Rikta Framework
4
- *
5
- * A modern TypeScript backend framework with zero-config autowiring, powered by Fastify.
6
- *
7
- * Features:
8
- * - Decorator-based routing (@Controller, @Get, @Post, etc.)
9
- * - Full Autowiring - No modules needed, everything is auto-discovered
10
- * - Single DI decorator - @Autowired() for constructor and property injection
11
- * - Hybrid Lifecycle - Interface hooks + EventBus
12
- * - Exception Handling - Built-in filters with standardized JSON responses
13
- * - Fastify under the hood for maximum performance
14
- * - Full TypeScript support
15
- *
16
- * @example
17
- * ```typescript
18
- * import { Rikta, Controller, Get, Injectable, Autowired } from '@rikta/core';
19
- *
20
- * @Injectable()
21
- * class GreetingService {
22
- * getGreeting(): string {
23
- * return 'Hello from Rikta!';
24
- * }
25
- * }
26
- *
27
- * @Controller()
28
- * class AppController {
29
- * @Autowired()
30
- * private greetingService!: GreetingService;
31
- *
32
- * @Get('/')
33
- * getHello() {
34
- * return this.greetingService.getGreeting();
35
- * }
36
- * }
37
- *
38
- * // No modules - just create and run!
39
- * const app = await Rikta.create({ port: 3000 });
40
- * await app.listen();
41
- * ```
42
- */
43
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
44
3
  if (k2 === undefined) k2 = k;
45
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -56,9 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
56
15
  };
57
16
  Object.defineProperty(exports, "__esModule", { value: true });
58
17
  exports.default = void 0;
59
- // Re-export everything from core
60
18
  __exportStar(require("./core"), exports);
61
- // Default export for convenience
62
19
  var application_1 = require("./core/application");
63
20
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return application_1.RiktaFactory; } });
64
- //# sourceMappingURL=index.js.map