@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
@@ -1,24 +1,3 @@
1
- /**
2
- * Injection Token
3
- *
4
- * Used to identify dependencies that are not classes (interfaces, values, etc.)
5
- * Similar to NestJS InjectionToken and Angular's InjectionToken.
6
- *
7
- * @example
8
- * ```typescript
9
- * // Define a token for a configuration object
10
- * const CONFIG_TOKEN = new InjectionToken<AppConfig>('app.config');
11
- *
12
- * // Register with the container
13
- * container.registerValue(CONFIG_TOKEN, { apiUrl: 'https://api.example.com' });
14
- *
15
- * // Inject using the token
16
- * @Injectable()
17
- * class ApiService {
18
- * constructor(@Autowired(CONFIG_TOKEN) private config: AppConfig) {}
19
- * }
20
- * ```
21
- */
22
1
  export declare class InjectionToken<T = unknown> {
23
2
  readonly description: string;
24
3
  readonly options?: {
@@ -29,14 +8,7 @@ export declare class InjectionToken<T = unknown> {
29
8
  } | undefined);
30
9
  toString(): string;
31
10
  }
32
- /**
33
- * Type for any valid injection token
34
- * Can be a class constructor, InjectionToken, string, or symbol
35
- */
36
11
  export type Token<T = unknown> = (new (...args: unknown[]) => T) | InjectionToken<T> | string | symbol;
37
- /**
38
- * Provider definition for custom providers
39
- */
40
12
  export interface ClassProvider<T = unknown> {
41
13
  provide: Token<T>;
42
14
  useClass: new (...args: unknown[]) => T;
@@ -55,4 +27,3 @@ export interface ExistingProvider<T = unknown> {
55
27
  useExisting: Token<T>;
56
28
  }
57
29
  export type ProviderDefinition<T = unknown> = ClassProvider<T> | ValueProvider<T> | FactoryProvider<T> | ExistingProvider<T> | (new (...args: unknown[]) => T);
58
- //# sourceMappingURL=injection-token.d.ts.map
@@ -1,27 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InjectionToken = void 0;
4
- /**
5
- * Injection Token
6
- *
7
- * Used to identify dependencies that are not classes (interfaces, values, etc.)
8
- * Similar to NestJS InjectionToken and Angular's InjectionToken.
9
- *
10
- * @example
11
- * ```typescript
12
- * // Define a token for a configuration object
13
- * const CONFIG_TOKEN = new InjectionToken<AppConfig>('app.config');
14
- *
15
- * // Register with the container
16
- * container.registerValue(CONFIG_TOKEN, { apiUrl: 'https://api.example.com' });
17
- *
18
- * // Inject using the token
19
- * @Injectable()
20
- * class ApiService {
21
- * constructor(@Autowired(CONFIG_TOKEN) private config: AppConfig) {}
22
- * }
23
- * ```
24
- */
25
4
  class InjectionToken {
26
5
  description;
27
6
  options;
@@ -34,4 +13,3 @@ class InjectionToken {
34
13
  }
35
14
  }
36
15
  exports.InjectionToken = InjectionToken;
37
- //# sourceMappingURL=injection-token.js.map
@@ -1,72 +1,10 @@
1
1
  import 'reflect-metadata';
2
2
  import { Token } from '../container/injection-token';
3
- /**
4
- * Metadata for autowired parameters/properties
5
- */
6
3
  export interface AutowiredMetadata {
7
4
  token: Token;
8
5
  index?: number;
9
6
  propertyKey?: string;
10
7
  optional?: boolean;
11
8
  }
12
- /**
13
- * @Autowired() decorator
14
- *
15
- * Universal dependency injection decorator for both:
16
- * - Constructor parameters
17
- * - Class properties
18
- *
19
- * Automatically infers the type when no token is provided.
20
- *
21
- * @example Property injection (most common):
22
- * ```typescript
23
- * @Controller('/users')
24
- * export class UserController {
25
- * @Autowired()
26
- * private userService!: UserService;
27
- *
28
- * @Autowired(LOGGER) // With token for interfaces
29
- * private logger!: Logger;
30
- * }
31
- * ```
32
- *
33
- * @example Constructor injection:
34
- * ```typescript
35
- * @Injectable()
36
- * class ApiService {
37
- * constructor(
38
- * @Autowired() private userService: UserService,
39
- * @Autowired(CONFIG) private config: AppConfig
40
- * ) {}
41
- * }
42
- * ```
43
- */
44
9
  export declare function Autowired(token?: Token): ParameterDecorator & PropertyDecorator;
45
- /**
46
- * @Optional() decorator
47
- *
48
- * Marks an injection as optional. If the dependency is not found,
49
- * undefined will be injected instead of throwing an error.
50
- *
51
- * @example Property injection:
52
- * ```typescript
53
- * @Controller()
54
- * export class AppController {
55
- * @Optional()
56
- * @Autowired()
57
- * private analytics?: AnalyticsService;
58
- * }
59
- * ```
60
- *
61
- * @example Constructor injection:
62
- * ```typescript
63
- * @Injectable()
64
- * class NotificationService {
65
- * constructor(
66
- * @Optional() @Autowired(SLACK) private slack?: SlackClient
67
- * ) {}
68
- * }
69
- * ```
70
- */
71
10
  export declare function Optional(): ParameterDecorator & PropertyDecorator;
72
- //# sourceMappingURL=autowired.decorator.d.ts.map
@@ -4,42 +4,9 @@ exports.Autowired = Autowired;
4
4
  exports.Optional = Optional;
5
5
  require("reflect-metadata");
6
6
  const constants_1 = require("../constants");
7
- /**
8
- * @Autowired() decorator
9
- *
10
- * Universal dependency injection decorator for both:
11
- * - Constructor parameters
12
- * - Class properties
13
- *
14
- * Automatically infers the type when no token is provided.
15
- *
16
- * @example Property injection (most common):
17
- * ```typescript
18
- * @Controller('/users')
19
- * export class UserController {
20
- * @Autowired()
21
- * private userService!: UserService;
22
- *
23
- * @Autowired(LOGGER) // With token for interfaces
24
- * private logger!: Logger;
25
- * }
26
- * ```
27
- *
28
- * @example Constructor injection:
29
- * ```typescript
30
- * @Injectable()
31
- * class ApiService {
32
- * constructor(
33
- * @Autowired() private userService: UserService,
34
- * @Autowired(CONFIG) private config: AppConfig
35
- * ) {}
36
- * }
37
- * ```
38
- */
39
7
  function Autowired(token) {
40
8
  return (target, propertyKey, parameterIndex) => {
41
9
  if (typeof parameterIndex === 'number') {
42
- // Constructor parameter injection
43
10
  const paramTypes = Reflect.getMetadata('design:paramtypes', target) ?? [];
44
11
  const inferredType = paramTypes[parameterIndex];
45
12
  const resolvedToken = token ?? inferredType;
@@ -55,7 +22,6 @@ function Autowired(token) {
55
22
  Reflect.defineMetadata(constants_1.INJECT_METADATA, existingInjects, target);
56
23
  }
57
24
  else if (propertyKey !== undefined) {
58
- // Property injection
59
25
  const inferredType = Reflect.getMetadata('design:type', target, propertyKey);
60
26
  const resolvedToken = token ?? inferredType;
61
27
  if (!resolvedToken) {
@@ -71,36 +37,9 @@ function Autowired(token) {
71
37
  }
72
38
  };
73
39
  }
74
- /**
75
- * @Optional() decorator
76
- *
77
- * Marks an injection as optional. If the dependency is not found,
78
- * undefined will be injected instead of throwing an error.
79
- *
80
- * @example Property injection:
81
- * ```typescript
82
- * @Controller()
83
- * export class AppController {
84
- * @Optional()
85
- * @Autowired()
86
- * private analytics?: AnalyticsService;
87
- * }
88
- * ```
89
- *
90
- * @example Constructor injection:
91
- * ```typescript
92
- * @Injectable()
93
- * class NotificationService {
94
- * constructor(
95
- * @Optional() @Autowired(SLACK) private slack?: SlackClient
96
- * ) {}
97
- * }
98
- * ```
99
- */
100
40
  function Optional() {
101
41
  return (target, propertyKey, parameterIndex) => {
102
42
  if (typeof parameterIndex === 'number') {
103
- // Constructor parameter
104
43
  const existingInjects = Reflect.getMetadata(constants_1.INJECT_METADATA, target) ?? [];
105
44
  let meta = existingInjects.find(m => m.index === parameterIndex);
106
45
  if (meta) {
@@ -120,7 +59,6 @@ function Optional() {
120
59
  Reflect.defineMetadata(constants_1.INJECT_METADATA, existingInjects, target);
121
60
  }
122
61
  else if (propertyKey !== undefined) {
123
- // Property injection
124
62
  const existingAutowires = Reflect.getMetadata(constants_1.AUTOWIRED_METADATA, target.constructor) ?? [];
125
63
  let meta = existingAutowires.find(m => m.propertyKey === String(propertyKey));
126
64
  if (meta) {
@@ -140,4 +78,3 @@ function Optional() {
140
78
  }
141
79
  };
142
80
  }
143
- //# sourceMappingURL=autowired.decorator.js.map
@@ -1,129 +1,9 @@
1
1
  import 'reflect-metadata';
2
- /**
3
- * Metadata for a single config property mapping
4
- */
5
2
  export interface ConfigPropertyMapping {
6
- /**
7
- * The property name on the class
8
- */
9
3
  propertyKey: string;
10
- /**
11
- * The environment variable name to map from
12
- */
13
4
  envKey: string;
14
5
  }
15
- /**
16
- * @ConfigProperty() decorator
17
- *
18
- * Maps a class property to an environment variable. If no explicit env key is provided,
19
- * automatically converts the property name from camelCase to UPPER_SNAKE_CASE.
20
- *
21
- * This decorator stores metadata that will be read by AbstractConfigProvider
22
- * during the populate() phase to assign validated environment values to properties.
23
- *
24
- * @param envKey - Optional explicit environment variable name (must be UPPERCASE)
25
- *
26
- * @example Auto-mapping (property name → UPPER_SNAKE_CASE):
27
- * ```typescript
28
- * import { ConfigProperty, Provider, AbstractConfigProvider } from '@riktajs/core';
29
- * import { z } from 'zod';
30
- *
31
- * @Provider()
32
- * export class DatabaseConfigProvider extends AbstractConfigProvider {
33
- * schema() {
34
- * return z.object({
35
- * DB_HOST: z.string(),
36
- * DB_PORT: z.coerce.number().int(),
37
- * DB_NAME: z.string(),
38
- * });
39
- * }
40
- *
41
- * @ConfigProperty() // Maps to 'DB_HOST'
42
- * dbHost!: string;
43
- *
44
- * @ConfigProperty() // Maps to 'DB_PORT'
45
- * dbPort!: number;
46
- *
47
- * @ConfigProperty() // Maps to 'DB_NAME'
48
- * dbName!: string;
49
- * }
50
- * ```
51
- *
52
- * @example Custom env key mapping:
53
- * ```typescript
54
- * @Provider()
55
- * export class AppConfigProvider extends AbstractConfigProvider {
56
- * schema() {
57
- * return z.object({
58
- * PORT: z.coerce.number().int(),
59
- * NODE_ENV: z.enum(['development', 'production', 'test']),
60
- * API_SECRET_KEY: z.string(),
61
- * });
62
- * }
63
- *
64
- * @ConfigProperty('PORT')
65
- * serverPort!: number;
66
- *
67
- * @ConfigProperty('NODE_ENV')
68
- * environment!: 'development' | 'production' | 'test';
69
- *
70
- * @ConfigProperty('API_SECRET_KEY')
71
- * secret!: string;
72
- * }
73
- * ```
74
- *
75
- * @example Mixed auto and custom mapping:
76
- * ```typescript
77
- * @Provider()
78
- * export class ApiConfigProvider extends AbstractConfigProvider {
79
- * schema() {
80
- * return z.object({
81
- * API_KEY: z.string(),
82
- * API_URL: z.string().url(),
83
- * TIMEOUT: z.coerce.number().int(),
84
- * });
85
- * }
86
- *
87
- * @ConfigProperty() // Auto: apiKey → API_KEY
88
- * apiKey!: string;
89
- *
90
- * @ConfigProperty() // Auto: apiUrl → API_URL
91
- * apiUrl!: string;
92
- *
93
- * @ConfigProperty('TIMEOUT') // Custom mapping
94
- * requestTimeout!: number;
95
- * }
96
- * ```
97
- */
98
6
  export declare function ConfigProperty(envKey?: string): PropertyDecorator;
99
- /**
100
- * Helper to retrieve all config property mappings from a class
101
- *
102
- * @param target - The class constructor to retrieve mappings from
103
- * @returns Array of property mappings, or empty array if none defined
104
- *
105
- * @example
106
- * ```typescript
107
- * const mappings = getConfigPropertyMappings(AppConfigProvider);
108
- * console.log(mappings);
109
- * // [
110
- * // { propertyKey: 'dbHost', envKey: 'DB_HOST' },
111
- * // { propertyKey: 'dbPort', envKey: 'DB_PORT' }
112
- * // ]
113
- * ```
114
- */
115
7
  export declare function getConfigPropertyMappings(target: Function): ConfigPropertyMapping[];
116
- /**
117
- * Check if a class has any @ConfigProperty decorated properties
118
- *
119
- * @param target - The class constructor to check
120
- * @returns True if the class has at least one @ConfigProperty
121
- */
122
8
  export declare function hasConfigProperties(target: Function): boolean;
123
- /**
124
- * Clear the property name conversion cache
125
- *
126
- * @internal Used for testing
127
- */
128
9
  export declare function clearPropertyNameCache(): void;
129
- //# sourceMappingURL=config-property.decorator.d.ts.map
@@ -6,200 +6,60 @@ exports.hasConfigProperties = hasConfigProperties;
6
6
  exports.clearPropertyNameCache = clearPropertyNameCache;
7
7
  require("reflect-metadata");
8
8
  const constants_1 = require("../constants");
9
- /**
10
- * Cache for converted property names to avoid recomputation
11
- * Map<propertyKey, envKey>
12
- */
13
9
  const propertyNameCache = new Map();
14
- /**
15
- * Convert a camelCase property name to UPPER_SNAKE_CASE
16
- *
17
- * @param propertyName - The property name to convert
18
- * @returns The converted UPPER_SNAKE_CASE name
19
- *
20
- * @example
21
- * ```typescript
22
- * toUpperSnakeCase('dbHost') // 'DB_HOST'
23
- * toUpperSnakeCase('apiKey') // 'API_KEY'
24
- * toUpperSnakeCase('port') // 'PORT'
25
- * toUpperSnakeCase('maxRetries') // 'MAX_RETRIES'
26
- * ```
27
- */
28
10
  function toUpperSnakeCase(propertyName) {
29
- // Check cache first (tip: cache derived names)
30
11
  if (propertyNameCache.has(propertyName)) {
31
12
  return propertyNameCache.get(propertyName);
32
13
  }
33
- // Convert camelCase/PascalCase to UPPER_SNAKE_CASE
34
14
  const envKey = propertyName
35
15
  .replace(/([A-Z])/g, '_$1')
36
16
  .toUpperCase()
37
17
  .replace(/^_/, '');
38
- // Cache for future use
39
18
  propertyNameCache.set(propertyName, envKey);
40
19
  return envKey;
41
20
  }
42
- /**
43
- * @ConfigProperty() decorator
44
- *
45
- * Maps a class property to an environment variable. If no explicit env key is provided,
46
- * automatically converts the property name from camelCase to UPPER_SNAKE_CASE.
47
- *
48
- * This decorator stores metadata that will be read by AbstractConfigProvider
49
- * during the populate() phase to assign validated environment values to properties.
50
- *
51
- * @param envKey - Optional explicit environment variable name (must be UPPERCASE)
52
- *
53
- * @example Auto-mapping (property name → UPPER_SNAKE_CASE):
54
- * ```typescript
55
- * import { ConfigProperty, Provider, AbstractConfigProvider } from '@riktajs/core';
56
- * import { z } from 'zod';
57
- *
58
- * @Provider()
59
- * export class DatabaseConfigProvider extends AbstractConfigProvider {
60
- * schema() {
61
- * return z.object({
62
- * DB_HOST: z.string(),
63
- * DB_PORT: z.coerce.number().int(),
64
- * DB_NAME: z.string(),
65
- * });
66
- * }
67
- *
68
- * @ConfigProperty() // Maps to 'DB_HOST'
69
- * dbHost!: string;
70
- *
71
- * @ConfigProperty() // Maps to 'DB_PORT'
72
- * dbPort!: number;
73
- *
74
- * @ConfigProperty() // Maps to 'DB_NAME'
75
- * dbName!: string;
76
- * }
77
- * ```
78
- *
79
- * @example Custom env key mapping:
80
- * ```typescript
81
- * @Provider()
82
- * export class AppConfigProvider extends AbstractConfigProvider {
83
- * schema() {
84
- * return z.object({
85
- * PORT: z.coerce.number().int(),
86
- * NODE_ENV: z.enum(['development', 'production', 'test']),
87
- * API_SECRET_KEY: z.string(),
88
- * });
89
- * }
90
- *
91
- * @ConfigProperty('PORT')
92
- * serverPort!: number;
93
- *
94
- * @ConfigProperty('NODE_ENV')
95
- * environment!: 'development' | 'production' | 'test';
96
- *
97
- * @ConfigProperty('API_SECRET_KEY')
98
- * secret!: string;
99
- * }
100
- * ```
101
- *
102
- * @example Mixed auto and custom mapping:
103
- * ```typescript
104
- * @Provider()
105
- * export class ApiConfigProvider extends AbstractConfigProvider {
106
- * schema() {
107
- * return z.object({
108
- * API_KEY: z.string(),
109
- * API_URL: z.string().url(),
110
- * TIMEOUT: z.coerce.number().int(),
111
- * });
112
- * }
113
- *
114
- * @ConfigProperty() // Auto: apiKey → API_KEY
115
- * apiKey!: string;
116
- *
117
- * @ConfigProperty() // Auto: apiUrl → API_URL
118
- * apiUrl!: string;
119
- *
120
- * @ConfigProperty('TIMEOUT') // Custom mapping
121
- * requestTimeout!: number;
122
- * }
123
- * ```
124
- */
125
21
  function ConfigProperty(envKey) {
126
22
  return (target, propertyKey) => {
127
23
  if (typeof propertyKey === 'symbol') {
128
24
  throw new Error(`@ConfigProperty: Symbol properties are not supported. ` +
129
25
  `Property "${String(propertyKey)}" must be a string.`);
130
26
  }
131
- // Determine the environment variable name
132
27
  const finalEnvKey = envKey ?? toUpperSnakeCase(propertyKey);
133
- // Validate env key format
134
28
  if (!finalEnvKey || typeof finalEnvKey !== 'string') {
135
29
  throw new Error(`@ConfigProperty: Invalid env key for property "${propertyKey}". ` +
136
30
  `Env key must be a non-empty string.`);
137
31
  }
138
- // Ensure env key is uppercase (convention)
139
32
  if (finalEnvKey !== finalEnvKey.toUpperCase()) {
140
33
  throw new Error(`@ConfigProperty: Env key "${finalEnvKey}" for property "${propertyKey}" must be UPPERCASE. ` +
141
34
  `Use "${finalEnvKey.toUpperCase()}" instead.`);
142
35
  }
143
- // Get existing metadata or initialize
144
36
  const constructor = target.constructor;
145
37
  const existingMappings = Reflect.getMetadata(constants_1.CONFIG_PROPERTY_METADATA, constructor) || [];
146
- // Check for duplicate property decorations
147
38
  const duplicate = existingMappings.find(m => m.propertyKey === propertyKey);
148
39
  if (duplicate) {
149
40
  throw new Error(`@ConfigProperty: Property "${propertyKey}" on class "${constructor.name}" ` +
150
41
  `is already decorated. Remove the duplicate @ConfigProperty decorator.`);
151
42
  }
152
- // Check for duplicate env key mappings
153
43
  const duplicateEnvKey = existingMappings.find(m => m.envKey === finalEnvKey);
154
44
  if (duplicateEnvKey) {
155
45
  throw new Error(`@ConfigProperty: Env key "${finalEnvKey}" is already mapped to property "${duplicateEnvKey.propertyKey}" ` +
156
46
  `on class "${constructor.name}". Each env key can only be mapped to one property.`);
157
47
  }
158
- // Add the new mapping
159
48
  const newMapping = {
160
49
  propertyKey,
161
50
  envKey: finalEnvKey,
162
51
  };
163
52
  const updatedMappings = [...existingMappings, newMapping];
164
- // Store metadata
165
53
  Reflect.defineMetadata(constants_1.CONFIG_PROPERTY_METADATA, updatedMappings, constructor);
166
54
  };
167
55
  }
168
- /**
169
- * Helper to retrieve all config property mappings from a class
170
- *
171
- * @param target - The class constructor to retrieve mappings from
172
- * @returns Array of property mappings, or empty array if none defined
173
- *
174
- * @example
175
- * ```typescript
176
- * const mappings = getConfigPropertyMappings(AppConfigProvider);
177
- * console.log(mappings);
178
- * // [
179
- * // { propertyKey: 'dbHost', envKey: 'DB_HOST' },
180
- * // { propertyKey: 'dbPort', envKey: 'DB_PORT' }
181
- * // ]
182
- * ```
183
- */
184
56
  function getConfigPropertyMappings(target) {
185
57
  return Reflect.getMetadata(constants_1.CONFIG_PROPERTY_METADATA, target) || [];
186
58
  }
187
- /**
188
- * Check if a class has any @ConfigProperty decorated properties
189
- *
190
- * @param target - The class constructor to check
191
- * @returns True if the class has at least one @ConfigProperty
192
- */
193
59
  function hasConfigProperties(target) {
194
60
  const mappings = getConfigPropertyMappings(target);
195
61
  return mappings.length > 0;
196
62
  }
197
- /**
198
- * Clear the property name conversion cache
199
- *
200
- * @internal Used for testing
201
- */
202
63
  function clearPropertyNameCache() {
203
64
  propertyNameCache.clear();
204
65
  }
205
- //# sourceMappingURL=config-property.decorator.js.map
@@ -1,33 +1,5 @@
1
1
  import 'reflect-metadata';
2
- /**
3
- * Controller options
4
- */
5
2
  export interface ControllerOptions {
6
- /** Route prefix for all routes in this controller */
7
3
  prefix?: string;
8
4
  }
9
- /**
10
- * @Controller() decorator
11
- *
12
- * Marks a class as a controller that handles HTTP requests.
13
- * Controllers are automatically:
14
- * - Registered in the global registry for auto-discovery
15
- * - Injectable and registered in the DI container
16
- *
17
- * @example
18
- * ```typescript
19
- * @Controller('/users')
20
- * class UserController {
21
- * @Autowired()
22
- * private userService!: UserService;
23
- *
24
- * @Get('/')
25
- * getUsers() { return []; }
26
- *
27
- * @Get('/:id')
28
- * getUser(@Param('id') id: string) { return { id }; }
29
- * }
30
- * ```
31
- */
32
5
  export declare function Controller(prefixOrOptions?: string | ControllerOptions): ClassDecorator;
33
- //# sourceMappingURL=controller.decorator.d.ts.map
@@ -5,46 +5,17 @@ require("reflect-metadata");
5
5
  const constants_1 = require("../constants");
6
6
  const container_1 = require("../container/container");
7
7
  const registry_1 = require("../registry");
8
- /**
9
- * @Controller() decorator
10
- *
11
- * Marks a class as a controller that handles HTTP requests.
12
- * Controllers are automatically:
13
- * - Registered in the global registry for auto-discovery
14
- * - Injectable and registered in the DI container
15
- *
16
- * @example
17
- * ```typescript
18
- * @Controller('/users')
19
- * class UserController {
20
- * @Autowired()
21
- * private userService!: UserService;
22
- *
23
- * @Get('/')
24
- * getUsers() { return []; }
25
- *
26
- * @Get('/:id')
27
- * getUser(@Param('id') id: string) { return { id }; }
28
- * }
29
- * ```
30
- */
31
8
  function Controller(prefixOrOptions) {
32
9
  return (target) => {
33
10
  const prefix = typeof prefixOrOptions === 'string'
34
11
  ? prefixOrOptions
35
12
  : prefixOrOptions?.prefix ?? '';
36
- // Normalize prefix (ensure it starts with / if not empty)
37
13
  const normalizedPrefix = prefix
38
14
  ? (prefix.startsWith('/') ? prefix : `/${prefix}`)
39
15
  : '';
40
- // Store controller metadata
41
16
  Reflect.defineMetadata(constants_1.CONTROLLER_METADATA, { prefix: normalizedPrefix }, target);
42
- // Mark as injectable
43
17
  Reflect.defineMetadata(constants_1.INJECTABLE_METADATA, { scope: 'singleton' }, target);
44
- // Register in DI container
45
18
  container_1.container.register(target, { scope: 'singleton' });
46
- // Auto-register in global registry for discovery
47
19
  registry_1.registry.registerController(target);
48
20
  };
49
21
  }
50
- //# sourceMappingURL=controller.decorator.js.map
@@ -5,4 +5,3 @@ export * from './param.decorator';
5
5
  export * from './autowired.decorator';
6
6
  export * from './provider.decorator';
7
7
  export * from './config-property.decorator';
8
- //# sourceMappingURL=index.d.ts.map
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- // Export all decorators
18
17
  __exportStar(require("./injectable.decorator"), exports);
19
18
  __exportStar(require("./controller.decorator"), exports);
20
19
  __exportStar(require("./route.decorator"), exports);
@@ -22,4 +21,3 @@ __exportStar(require("./param.decorator"), exports);
22
21
  __exportStar(require("./autowired.decorator"), exports);
23
22
  __exportStar(require("./provider.decorator"), exports);
24
23
  __exportStar(require("./config-property.decorator"), exports);
25
- //# sourceMappingURL=index.js.map