@riktajs/core 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +132 -54
  2. package/dist/core/application.d.ts +1 -1
  3. package/dist/core/application.js +51 -45
  4. package/dist/core/config/abstract-config-provider.js +8 -13
  5. package/dist/core/config/env-loader.js +12 -17
  6. package/dist/core/config/index.d.ts +2 -2
  7. package/dist/core/config/index.js +2 -18
  8. package/dist/core/constants.js +18 -21
  9. package/dist/core/container/abstract-class.utils.d.ts +1 -1
  10. package/dist/core/container/abstract-class.utils.js +14 -24
  11. package/dist/core/container/container.d.ts +2 -2
  12. package/dist/core/container/container.js +47 -19
  13. package/dist/core/container/implements.decorator.d.ts +1 -1
  14. package/dist/core/container/implements.decorator.js +17 -23
  15. package/dist/core/container/index.d.ts +5 -4
  16. package/dist/core/container/index.js +5 -20
  17. package/dist/core/container/injection-token.js +1 -5
  18. package/dist/core/container/request-scope.d.ts +16 -0
  19. package/dist/core/container/request-scope.js +49 -0
  20. package/dist/core/decorators/apply-decorators.js +3 -7
  21. package/dist/core/decorators/autowired.decorator.d.ts +1 -1
  22. package/dist/core/decorators/autowired.decorator.js +12 -16
  23. package/dist/core/decorators/config-property.decorator.js +9 -15
  24. package/dist/core/decorators/controller.decorator.js +9 -12
  25. package/dist/core/decorators/create-param-decorator.d.ts +1 -1
  26. package/dist/core/decorators/create-param-decorator.js +7 -12
  27. package/dist/core/decorators/index.d.ts +9 -9
  28. package/dist/core/decorators/index.js +9 -25
  29. package/dist/core/decorators/injectable.decorator.d.ts +1 -1
  30. package/dist/core/decorators/injectable.decorator.js +8 -11
  31. package/dist/core/decorators/param.decorator.d.ts +1 -1
  32. package/dist/core/decorators/param.decorator.js +14 -17
  33. package/dist/core/decorators/provider.decorator.d.ts +2 -2
  34. package/dist/core/decorators/provider.decorator.js +12 -17
  35. package/dist/core/decorators/route.decorator.js +13 -17
  36. package/dist/core/discovery.d.ts +2 -1
  37. package/dist/core/discovery.js +44 -64
  38. package/dist/core/exceptions/catch.decorator.d.ts +1 -1
  39. package/dist/core/exceptions/catch.decorator.js +6 -11
  40. package/dist/core/exceptions/config.exceptions.js +3 -9
  41. package/dist/core/exceptions/discovery.exception.d.ts +18 -0
  42. package/dist/core/exceptions/discovery.exception.js +39 -0
  43. package/dist/core/exceptions/exception-filter.js +5 -10
  44. package/dist/core/exceptions/exceptions.d.ts +1 -1
  45. package/dist/core/exceptions/exceptions.js +19 -40
  46. package/dist/core/exceptions/http-exception.js +1 -5
  47. package/dist/core/exceptions/index.d.ts +7 -6
  48. package/dist/core/exceptions/index.js +7 -37
  49. package/dist/core/exceptions/validation.exception.d.ts +1 -1
  50. package/dist/core/exceptions/validation.exception.js +2 -6
  51. package/dist/core/guards/can-activate.interface.d.ts +1 -1
  52. package/dist/core/guards/can-activate.interface.js +1 -2
  53. package/dist/core/guards/execution-context.d.ts +8 -1
  54. package/dist/core/guards/execution-context.js +9 -5
  55. package/dist/core/guards/index.d.ts +3 -3
  56. package/dist/core/guards/index.js +2 -8
  57. package/dist/core/guards/use-guards.decorator.d.ts +2 -2
  58. package/dist/core/guards/use-guards.decorator.js +10 -14
  59. package/dist/core/index.d.ts +16 -14
  60. package/dist/core/index.js +17 -33
  61. package/dist/core/interceptors/index.d.ts +2 -0
  62. package/dist/core/interceptors/index.js +1 -0
  63. package/dist/core/interceptors/interceptor.interface.d.ts +7 -0
  64. package/dist/core/interceptors/interceptor.interface.js +1 -0
  65. package/dist/core/interceptors/use-interceptors.decorator.d.ts +6 -0
  66. package/dist/core/interceptors/use-interceptors.decorator.js +19 -0
  67. package/dist/core/lifecycle/event-bus.d.ts +10 -5
  68. package/dist/core/lifecycle/event-bus.js +61 -14
  69. package/dist/core/lifecycle/index.d.ts +3 -3
  70. package/dist/core/lifecycle/index.js +3 -19
  71. package/dist/core/lifecycle/interfaces.js +1 -2
  72. package/dist/core/lifecycle/on.decorator.d.ts +1 -1
  73. package/dist/core/lifecycle/on.decorator.js +5 -9
  74. package/dist/core/metadata.d.ts +2 -2
  75. package/dist/core/metadata.js +26 -43
  76. package/dist/core/middleware/index.d.ts +3 -3
  77. package/dist/core/middleware/index.js +2 -9
  78. package/dist/core/middleware/middleware.decorator.js +2 -5
  79. package/dist/core/middleware/rikta-middleware.interface.js +1 -2
  80. package/dist/core/middleware/use-middleware.decorator.d.ts +2 -2
  81. package/dist/core/middleware/use-middleware.decorator.js +10 -14
  82. package/dist/core/profiler/index.d.ts +2 -0
  83. package/dist/core/profiler/index.js +1 -0
  84. package/dist/core/profiler/performance-profiler.d.ts +42 -0
  85. package/dist/core/profiler/performance-profiler.js +95 -0
  86. package/dist/core/registry.d.ts +1 -3
  87. package/dist/core/registry.js +4 -39
  88. package/dist/core/router/router.d.ts +12 -2
  89. package/dist/core/router/router.js +112 -39
  90. package/dist/core/types.d.ts +8 -4
  91. package/dist/core/types.js +1 -2
  92. package/dist/index.d.ts +2 -2
  93. package/dist/index.js +2 -20
  94. package/package.json +8 -1
@@ -1,12 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.container = exports.Container = void 0;
4
- require("reflect-metadata");
5
- const constants_1 = require("../constants");
6
- const injection_token_1 = require("./injection-token");
7
- const registry_1 = require("../registry");
8
- const abstract_class_utils_1 = require("./abstract-class.utils");
9
- class Container {
1
+ import 'reflect-metadata';
2
+ import { INJECT_METADATA, AUTOWIRED_METADATA } from '../constants.js';
3
+ import { InjectionToken } from './injection-token.js';
4
+ import { registry } from '../registry.js';
5
+ import { isAbstractClass } from './abstract-class.utils.js';
6
+ import { requestScopeStorage } from './request-scope.js';
7
+ export class Container {
10
8
  static instance;
11
9
  singletons = new Map();
12
10
  providers = new Map();
@@ -79,7 +77,7 @@ class Container {
79
77
  this.singletons.set(token, instance);
80
78
  return instance;
81
79
  }
82
- if (!(0, abstract_class_utils_1.isAbstractClass)(token)) {
80
+ if (!isAbstractClass(token)) {
83
81
  return this.resolveClass(token);
84
82
  }
85
83
  }
@@ -97,14 +95,32 @@ class Container {
97
95
  throw new Error(`Cannot resolve token: ${this.getTokenName(token)}`);
98
96
  }
99
97
  resolveAbstractClass(abstractClass, name) {
100
- if (name) {
101
- return registry_1.registry.resolveImplementation(abstractClass, name);
102
- }
103
98
  const config = this.providers.get(abstractClass);
104
99
  if (config?.provider && 'useClass' in config.provider) {
105
100
  return config.provider.useClass;
106
101
  }
107
- return registry_1.registry.resolveImplementation(abstractClass);
102
+ const implementations = registry.getImplementations(abstractClass);
103
+ if (!implementations || implementations.length === 0) {
104
+ return undefined;
105
+ }
106
+ if (name) {
107
+ const named = implementations.find(i => i.name === name);
108
+ if (named) {
109
+ return named.implementation;
110
+ }
111
+ throw new Error(`No implementation named '${name}' found for abstract class ${abstractClass.name}. ` +
112
+ `Available names: ${implementations.filter(i => i.name).map(i => i.name).join(', ') || 'none'}`);
113
+ }
114
+ if (implementations.length === 1) {
115
+ return implementations[0].implementation;
116
+ }
117
+ const primary = implementations.find(i => i.isPrimary);
118
+ if (primary) {
119
+ return primary.implementation;
120
+ }
121
+ const implNames = implementations.map(i => i.implementation.name).join(', ');
122
+ throw new Error(`Multiple implementations found for abstract class ${abstractClass.name}: ${implNames}. ` +
123
+ `Use @Primary() to mark one as the default, or @Named() for qualified injection.`);
108
124
  }
109
125
  resolveProvider(provider, scope) {
110
126
  if (typeof provider === 'function') {
@@ -148,9 +164,19 @@ class Container {
148
164
  if (scope === 'singleton' && this.singletons.has(target)) {
149
165
  return this.singletons.get(target);
150
166
  }
167
+ if (scope === 'request') {
168
+ if (!requestScopeStorage.isInRequestScope()) {
169
+ throw new Error(`Cannot resolve request-scoped provider '${target.name}' outside of a request context. ` +
170
+ `Request-scoped providers can only be resolved during HTTP request handling.`);
171
+ }
172
+ const existingInstance = requestScopeStorage.get(target);
173
+ if (existingInstance !== undefined) {
174
+ return existingInstance;
175
+ }
176
+ }
151
177
  this.resolutionStack.add(target);
152
178
  try {
153
- const injectMeta = Reflect.getMetadata(constants_1.INJECT_METADATA, target) ?? [];
179
+ const injectMeta = Reflect.getMetadata(INJECT_METADATA, target) ?? [];
154
180
  const paramTypes = Reflect.getMetadata('design:paramtypes', target) ?? [];
155
181
  const maxIndex = injectMeta.length > 0
156
182
  ? Math.max(...injectMeta.map(m => m.index ?? -1))
@@ -188,6 +214,9 @@ class Container {
188
214
  if (scope === 'singleton') {
189
215
  this.singletons.set(target, instance);
190
216
  }
217
+ else if (scope === 'request') {
218
+ requestScopeStorage.set(target, instance);
219
+ }
191
220
  return instance;
192
221
  }
193
222
  finally {
@@ -195,7 +224,7 @@ class Container {
195
224
  }
196
225
  }
197
226
  injectProperties(target, instance) {
198
- const autowireMeta = Reflect.getMetadata(constants_1.AUTOWIRED_METADATA, target) ?? [];
227
+ const autowireMeta = Reflect.getMetadata(AUTOWIRED_METADATA, target) ?? [];
199
228
  for (const meta of autowireMeta) {
200
229
  if (!meta.propertyKey)
201
230
  continue;
@@ -251,7 +280,7 @@ class Container {
251
280
  if (typeof token === 'function') {
252
281
  return token.name;
253
282
  }
254
- if (token instanceof injection_token_1.InjectionToken) {
283
+ if (token instanceof InjectionToken) {
255
284
  return token.toString();
256
285
  }
257
286
  if (typeof token === 'symbol') {
@@ -260,5 +289,4 @@ class Container {
260
289
  return String(token);
261
290
  }
262
291
  }
263
- exports.Container = Container;
264
- exports.container = Container.getInstance();
292
+ export const container = Container.getInstance();
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { AnyConstructor } from '../types';
2
+ import { AnyConstructor } from '../types.js';
3
3
  export declare function Implements<T extends AnyConstructor>(abstractClass: T): ClassDecorator;
4
4
  export declare function Primary(): ClassDecorator;
5
5
  export declare function Named(name: string): ClassDecorator;
@@ -1,45 +1,39 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Implements = Implements;
4
- exports.Primary = Primary;
5
- exports.Named = Named;
6
- exports.AbstractClass = AbstractClass;
7
- require("reflect-metadata");
8
- const abstract_class_utils_1 = require("./abstract-class.utils");
9
- const registry_1 = require("../registry");
10
- function Implements(abstractClass) {
1
+ import 'reflect-metadata';
2
+ import { setImplementsMetadata, setPrimaryMetadata, markAsAbstract, IMPLEMENTS_METADATA } from './abstract-class.utils.js';
3
+ import { registry } from '../registry.js';
4
+ export function Implements(abstractClass) {
11
5
  return (target) => {
12
- (0, abstract_class_utils_1.setImplementsMetadata)(target, abstractClass);
13
- (0, abstract_class_utils_1.markAsAbstract)(abstractClass);
6
+ setImplementsMetadata(target, abstractClass);
7
+ markAsAbstract(abstractClass);
14
8
  const name = Reflect.getMetadata('rikta:named', target);
15
- registry_1.registry.registerAbstractImplementation(abstractClass, target, name);
9
+ registry.registerAbstractImplementation(abstractClass, target, name);
16
10
  const isPrimary = Reflect.getMetadata('rikta:is-primary', target) === true;
17
11
  if (isPrimary) {
18
- registry_1.registry.setPrimaryImplementation(abstractClass, target);
12
+ registry.setPrimaryImplementation(abstractClass, target);
19
13
  }
20
14
  };
21
15
  }
22
- function Primary() {
16
+ export function Primary() {
23
17
  return (target) => {
24
- (0, abstract_class_utils_1.setPrimaryMetadata)(target);
25
- const abstractClass = Reflect.getMetadata(abstract_class_utils_1.IMPLEMENTS_METADATA, target);
18
+ setPrimaryMetadata(target);
19
+ const abstractClass = Reflect.getMetadata(IMPLEMENTS_METADATA, target);
26
20
  if (abstractClass) {
27
- registry_1.registry.setPrimaryImplementation(abstractClass, target);
21
+ registry.setPrimaryImplementation(abstractClass, target);
28
22
  }
29
23
  Reflect.defineMetadata('rikta:is-primary', true, target);
30
24
  };
31
25
  }
32
- function Named(name) {
26
+ export function Named(name) {
33
27
  return (target) => {
34
28
  Reflect.defineMetadata('rikta:named', name, target);
35
- const abstractClass = Reflect.getMetadata(abstract_class_utils_1.IMPLEMENTS_METADATA, target);
29
+ const abstractClass = Reflect.getMetadata(IMPLEMENTS_METADATA, target);
36
30
  if (abstractClass) {
37
- registry_1.registry.setImplementationName(abstractClass, target, name);
31
+ registry.setImplementationName(abstractClass, target, name);
38
32
  }
39
33
  };
40
34
  }
41
- function AbstractClass() {
35
+ export function AbstractClass() {
42
36
  return (target) => {
43
- (0, abstract_class_utils_1.markAsAbstract)(target);
37
+ markAsAbstract(target);
44
38
  };
45
39
  }
@@ -1,4 +1,5 @@
1
- export * from './container';
2
- export * from './injection-token';
3
- export * from './abstract-class.utils';
4
- export * from './implements.decorator';
1
+ export * from './container.js';
2
+ export * from './injection-token.js';
3
+ export * from './abstract-class.utils.js';
4
+ export * from './implements.decorator.js';
5
+ export * from './request-scope.js';
@@ -1,20 +1,5 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./container"), exports);
18
- __exportStar(require("./injection-token"), exports);
19
- __exportStar(require("./abstract-class.utils"), exports);
20
- __exportStar(require("./implements.decorator"), exports);
1
+ export * from './container.js';
2
+ export * from './injection-token.js';
3
+ export * from './abstract-class.utils.js';
4
+ export * from './implements.decorator.js';
5
+ export * from './request-scope.js';
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InjectionToken = void 0;
4
- class InjectionToken {
1
+ export class InjectionToken {
5
2
  description;
6
3
  options;
7
4
  constructor(description, options) {
@@ -12,4 +9,3 @@ class InjectionToken {
12
9
  return `InjectionToken(${this.description})`;
13
10
  }
14
11
  }
15
- exports.InjectionToken = InjectionToken;
@@ -0,0 +1,16 @@
1
+ import { Token } from './injection-token.js';
2
+ export declare class RequestScopeStorage {
3
+ private static instance;
4
+ private readonly asyncLocalStorage;
5
+ private constructor();
6
+ static getInstance(): RequestScopeStorage;
7
+ static reset(): void;
8
+ run<T>(fn: () => T): T;
9
+ runAsync<T>(fn: () => Promise<T>): Promise<T>;
10
+ isInRequestScope(): boolean;
11
+ get<T>(token: Token<T>): T | undefined;
12
+ set<T>(token: Token<T>, instance: T): void;
13
+ has(token: Token): boolean;
14
+ getStore(): Map<Token, unknown> | undefined;
15
+ }
16
+ export declare const requestScopeStorage: RequestScopeStorage;
@@ -0,0 +1,49 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ export class RequestScopeStorage {
3
+ static instance;
4
+ asyncLocalStorage = new AsyncLocalStorage();
5
+ constructor() { }
6
+ static getInstance() {
7
+ if (!RequestScopeStorage.instance) {
8
+ RequestScopeStorage.instance = new RequestScopeStorage();
9
+ }
10
+ return RequestScopeStorage.instance;
11
+ }
12
+ static reset() {
13
+ RequestScopeStorage.instance = new RequestScopeStorage();
14
+ }
15
+ run(fn) {
16
+ const store = new Map();
17
+ return this.asyncLocalStorage.run(store, fn);
18
+ }
19
+ async runAsync(fn) {
20
+ const store = new Map();
21
+ return this.asyncLocalStorage.run(store, fn);
22
+ }
23
+ isInRequestScope() {
24
+ return this.asyncLocalStorage.getStore() !== undefined;
25
+ }
26
+ get(token) {
27
+ const store = this.asyncLocalStorage.getStore();
28
+ if (!store) {
29
+ return undefined;
30
+ }
31
+ return store.get(token);
32
+ }
33
+ set(token, instance) {
34
+ const store = this.asyncLocalStorage.getStore();
35
+ if (!store) {
36
+ throw new Error('Cannot set request-scoped instance outside of a request context. ' +
37
+ 'Make sure RequestScopeStorage.run() or runAsync() is being used.');
38
+ }
39
+ store.set(token, instance);
40
+ }
41
+ has(token) {
42
+ const store = this.asyncLocalStorage.getStore();
43
+ return store?.has(token) ?? false;
44
+ }
45
+ getStore() {
46
+ return this.asyncLocalStorage.getStore();
47
+ }
48
+ }
49
+ export const requestScopeStorage = RequestScopeStorage.getInstance();
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyDecorators = applyDecorators;
4
- exports.SetMetadata = SetMetadata;
5
- require("reflect-metadata");
6
- function applyDecorators(...decorators) {
1
+ import 'reflect-metadata';
2
+ export function applyDecorators(...decorators) {
7
3
  return ((target, propertyKey, descriptor) => {
8
4
  for (const decorator of decorators.reverse()) {
9
5
  if (descriptor) {
@@ -27,7 +23,7 @@ function applyDecorators(...decorators) {
27
23
  }
28
24
  });
29
25
  }
30
- function SetMetadata(key, value) {
26
+ export function SetMetadata(key, value) {
31
27
  const decoratorFactory = (target, propertyKey, descriptor) => {
32
28
  if (descriptor) {
33
29
  Reflect.defineMetadata(key, value, target.constructor, propertyKey);
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { Token } from '../container/injection-token';
2
+ import { Token } from '../container/injection-token.js';
3
3
  export interface AutowiredMetadata {
4
4
  token: Token;
5
5
  index?: number;
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Autowired = Autowired;
4
- exports.Optional = Optional;
5
- require("reflect-metadata");
6
- const constants_1 = require("../constants");
7
- function Autowired(token, name) {
1
+ import 'reflect-metadata';
2
+ import { INJECT_METADATA, AUTOWIRED_METADATA } from '../constants.js';
3
+ export function Autowired(token, name) {
8
4
  return (target, propertyKey, parameterIndex) => {
9
5
  if (typeof parameterIndex === 'number') {
10
6
  const paramTypes = Reflect.getMetadata('design:paramtypes', target) ?? [];
@@ -14,13 +10,13 @@ function Autowired(token, name) {
14
10
  throw new Error(`@Autowired() on constructor parameter ${parameterIndex} of ${target.name} ` +
15
11
  `could not infer type. Please provide a token explicitly.`);
16
12
  }
17
- const existingInjects = Reflect.getMetadata(constants_1.INJECT_METADATA, target) ?? [];
13
+ const existingInjects = Reflect.getMetadata(INJECT_METADATA, target) ?? [];
18
14
  existingInjects.push({
19
15
  token: resolvedToken,
20
16
  index: parameterIndex,
21
17
  name,
22
18
  });
23
- Reflect.defineMetadata(constants_1.INJECT_METADATA, existingInjects, target);
19
+ Reflect.defineMetadata(INJECT_METADATA, existingInjects, target);
24
20
  }
25
21
  else if (propertyKey !== undefined) {
26
22
  const inferredType = Reflect.getMetadata('design:type', target, propertyKey);
@@ -29,20 +25,20 @@ function Autowired(token, name) {
29
25
  throw new Error(`@Autowired() on ${target.constructor.name}.${String(propertyKey)} ` +
30
26
  `could not infer type. Please provide a token explicitly.`);
31
27
  }
32
- const existingAutowires = Reflect.getMetadata(constants_1.AUTOWIRED_METADATA, target.constructor) ?? [];
28
+ const existingAutowires = Reflect.getMetadata(AUTOWIRED_METADATA, target.constructor) ?? [];
33
29
  existingAutowires.push({
34
30
  token: resolvedToken,
35
31
  propertyKey: String(propertyKey),
36
32
  name,
37
33
  });
38
- Reflect.defineMetadata(constants_1.AUTOWIRED_METADATA, existingAutowires, target.constructor);
34
+ Reflect.defineMetadata(AUTOWIRED_METADATA, existingAutowires, target.constructor);
39
35
  }
40
36
  };
41
37
  }
42
- function Optional() {
38
+ export function Optional() {
43
39
  return (target, propertyKey, parameterIndex) => {
44
40
  if (typeof parameterIndex === 'number') {
45
- const existingInjects = Reflect.getMetadata(constants_1.INJECT_METADATA, target) ?? [];
41
+ const existingInjects = Reflect.getMetadata(INJECT_METADATA, target) ?? [];
46
42
  let meta = existingInjects.find(m => m.index === parameterIndex);
47
43
  if (meta) {
48
44
  meta.optional = true;
@@ -58,10 +54,10 @@ function Optional() {
58
54
  });
59
55
  }
60
56
  }
61
- Reflect.defineMetadata(constants_1.INJECT_METADATA, existingInjects, target);
57
+ Reflect.defineMetadata(INJECT_METADATA, existingInjects, target);
62
58
  }
63
59
  else if (propertyKey !== undefined) {
64
- const existingAutowires = Reflect.getMetadata(constants_1.AUTOWIRED_METADATA, target.constructor) ?? [];
60
+ const existingAutowires = Reflect.getMetadata(AUTOWIRED_METADATA, target.constructor) ?? [];
65
61
  let meta = existingAutowires.find(m => m.propertyKey === String(propertyKey));
66
62
  if (meta) {
67
63
  meta.optional = true;
@@ -76,7 +72,7 @@ function Optional() {
76
72
  });
77
73
  }
78
74
  }
79
- Reflect.defineMetadata(constants_1.AUTOWIRED_METADATA, existingAutowires, target.constructor);
75
+ Reflect.defineMetadata(AUTOWIRED_METADATA, existingAutowires, target.constructor);
80
76
  }
81
77
  };
82
78
  }
@@ -1,11 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfigProperty = ConfigProperty;
4
- exports.getConfigPropertyMappings = getConfigPropertyMappings;
5
- exports.hasConfigProperties = hasConfigProperties;
6
- exports.clearPropertyNameCache = clearPropertyNameCache;
7
- require("reflect-metadata");
8
- const constants_1 = require("../constants");
1
+ import 'reflect-metadata';
2
+ import { CONFIG_PROPERTY_METADATA } from '../constants.js';
9
3
  const propertyNameCache = new Map();
10
4
  function toUpperSnakeCase(propertyName) {
11
5
  if (propertyNameCache.has(propertyName)) {
@@ -18,7 +12,7 @@ function toUpperSnakeCase(propertyName) {
18
12
  propertyNameCache.set(propertyName, envKey);
19
13
  return envKey;
20
14
  }
21
- function ConfigProperty(envKey) {
15
+ export function ConfigProperty(envKey) {
22
16
  return (target, propertyKey) => {
23
17
  if (typeof propertyKey === 'symbol') {
24
18
  throw new Error(`@ConfigProperty: Symbol properties are not supported. ` +
@@ -34,7 +28,7 @@ function ConfigProperty(envKey) {
34
28
  `Use "${finalEnvKey.toUpperCase()}" instead.`);
35
29
  }
36
30
  const constructor = target.constructor;
37
- const existingMappings = Reflect.getMetadata(constants_1.CONFIG_PROPERTY_METADATA, constructor) || [];
31
+ const existingMappings = Reflect.getMetadata(CONFIG_PROPERTY_METADATA, constructor) || [];
38
32
  const duplicate = existingMappings.find(m => m.propertyKey === propertyKey);
39
33
  if (duplicate) {
40
34
  throw new Error(`@ConfigProperty: Property "${propertyKey}" on class "${constructor.name}" ` +
@@ -50,16 +44,16 @@ function ConfigProperty(envKey) {
50
44
  envKey: finalEnvKey,
51
45
  };
52
46
  const updatedMappings = [...existingMappings, newMapping];
53
- Reflect.defineMetadata(constants_1.CONFIG_PROPERTY_METADATA, updatedMappings, constructor);
47
+ Reflect.defineMetadata(CONFIG_PROPERTY_METADATA, updatedMappings, constructor);
54
48
  };
55
49
  }
56
- function getConfigPropertyMappings(target) {
57
- return Reflect.getMetadata(constants_1.CONFIG_PROPERTY_METADATA, target) || [];
50
+ export function getConfigPropertyMappings(target) {
51
+ return Reflect.getMetadata(CONFIG_PROPERTY_METADATA, target) || [];
58
52
  }
59
- function hasConfigProperties(target) {
53
+ export function hasConfigProperties(target) {
60
54
  const mappings = getConfigPropertyMappings(target);
61
55
  return mappings.length > 0;
62
56
  }
63
- function clearPropertyNameCache() {
57
+ export function clearPropertyNameCache() {
64
58
  propertyNameCache.clear();
65
59
  }
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Controller = Controller;
4
- require("reflect-metadata");
5
- const constants_1 = require("../constants");
6
- const container_1 = require("../container/container");
7
- const registry_1 = require("../registry");
8
- function Controller(prefixOrOptions) {
1
+ import 'reflect-metadata';
2
+ import { CONTROLLER_METADATA, INJECTABLE_METADATA } from '../constants.js';
3
+ import { container } from '../container/container.js';
4
+ import { registry } from '../registry.js';
5
+ export function Controller(prefixOrOptions) {
9
6
  return (target) => {
10
7
  const prefix = typeof prefixOrOptions === 'string'
11
8
  ? prefixOrOptions
@@ -13,9 +10,9 @@ function Controller(prefixOrOptions) {
13
10
  const normalizedPrefix = prefix
14
11
  ? (prefix.startsWith('/') ? prefix : `/${prefix}`)
15
12
  : '';
16
- Reflect.defineMetadata(constants_1.CONTROLLER_METADATA, { prefix: normalizedPrefix }, target);
17
- Reflect.defineMetadata(constants_1.INJECTABLE_METADATA, { scope: 'singleton' }, target);
18
- container_1.container.register(target, { scope: 'singleton' });
19
- registry_1.registry.registerController(target);
13
+ Reflect.defineMetadata(CONTROLLER_METADATA, { prefix: normalizedPrefix }, target);
14
+ Reflect.defineMetadata(INJECTABLE_METADATA, { scope: 'singleton' }, target);
15
+ container.register(target, { scope: 'singleton' });
16
+ registry.registerController(target);
20
17
  };
21
18
  }
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { ExecutionContext } from '../guards/execution-context';
2
+ import { ExecutionContext } from '../guards/execution-context.js';
3
3
  export declare const CUSTOM_PARAM_METADATA: unique symbol;
4
4
  export interface CustomParamMetadata<T = unknown> {
5
5
  index: number;
@@ -1,26 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CUSTOM_PARAM_METADATA = void 0;
4
- exports.createParamDecorator = createParamDecorator;
5
- exports.getCustomParamMetadata = getCustomParamMetadata;
6
- require("reflect-metadata");
7
- exports.CUSTOM_PARAM_METADATA = Symbol.for('rikta:custom:param:metadata');
8
- function createParamDecorator(factory) {
1
+ import 'reflect-metadata';
2
+ export const CUSTOM_PARAM_METADATA = Symbol.for('rikta:custom:param:metadata');
3
+ export function createParamDecorator(factory) {
9
4
  return (data) => {
10
5
  return (target, propertyKey, parameterIndex) => {
11
6
  if (propertyKey === undefined)
12
7
  return;
13
- const existingParams = Reflect.getMetadata(exports.CUSTOM_PARAM_METADATA, target.constructor, propertyKey) ?? [];
8
+ const existingParams = Reflect.getMetadata(CUSTOM_PARAM_METADATA, target.constructor, propertyKey) ?? [];
14
9
  const metadata = {
15
10
  index: parameterIndex,
16
11
  factory: factory,
17
12
  data,
18
13
  };
19
14
  existingParams.push(metadata);
20
- Reflect.defineMetadata(exports.CUSTOM_PARAM_METADATA, existingParams, target.constructor, propertyKey);
15
+ Reflect.defineMetadata(CUSTOM_PARAM_METADATA, existingParams, target.constructor, propertyKey);
21
16
  };
22
17
  };
23
18
  }
24
- function getCustomParamMetadata(target, propertyKey) {
25
- return Reflect.getMetadata(exports.CUSTOM_PARAM_METADATA, target, propertyKey) ?? [];
19
+ export function getCustomParamMetadata(target, propertyKey) {
20
+ return Reflect.getMetadata(CUSTOM_PARAM_METADATA, target, propertyKey) ?? [];
26
21
  }
@@ -1,9 +1,9 @@
1
- export * from './injectable.decorator';
2
- export * from './controller.decorator';
3
- export * from './route.decorator';
4
- export * from './param.decorator';
5
- export * from './autowired.decorator';
6
- export * from './provider.decorator';
7
- export * from './config-property.decorator';
8
- export * from './create-param-decorator';
9
- export * from './apply-decorators';
1
+ export * from './injectable.decorator.js';
2
+ export * from './controller.decorator.js';
3
+ export * from './route.decorator.js';
4
+ export * from './param.decorator.js';
5
+ export * from './autowired.decorator.js';
6
+ export * from './provider.decorator.js';
7
+ export * from './config-property.decorator.js';
8
+ export * from './create-param-decorator.js';
9
+ export * from './apply-decorators.js';
@@ -1,25 +1,9 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./injectable.decorator"), exports);
18
- __exportStar(require("./controller.decorator"), exports);
19
- __exportStar(require("./route.decorator"), exports);
20
- __exportStar(require("./param.decorator"), exports);
21
- __exportStar(require("./autowired.decorator"), exports);
22
- __exportStar(require("./provider.decorator"), exports);
23
- __exportStar(require("./config-property.decorator"), exports);
24
- __exportStar(require("./create-param-decorator"), exports);
25
- __exportStar(require("./apply-decorators"), exports);
1
+ export * from './injectable.decorator.js';
2
+ export * from './controller.decorator.js';
3
+ export * from './route.decorator.js';
4
+ export * from './param.decorator.js';
5
+ export * from './autowired.decorator.js';
6
+ export * from './provider.decorator.js';
7
+ export * from './config-property.decorator.js';
8
+ export * from './create-param-decorator.js';
9
+ export * from './apply-decorators.js';
@@ -1,3 +1,3 @@
1
1
  import 'reflect-metadata';
2
- import { InjectableOptions } from '../types';
2
+ import { InjectableOptions } from '../types.js';
3
3
  export declare function Injectable(options?: InjectableOptions): ClassDecorator;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Injectable = Injectable;
4
- require("reflect-metadata");
5
- const constants_1 = require("../constants");
6
- const container_1 = require("../container/container");
7
- const registry_1 = require("../registry");
8
- function Injectable(options = {}) {
1
+ import 'reflect-metadata';
2
+ import { INJECTABLE_METADATA } from '../constants.js';
3
+ import { container } from '../container/container.js';
4
+ import { registry } from '../registry.js';
5
+ export function Injectable(options = {}) {
9
6
  return (target) => {
10
- Reflect.defineMetadata(constants_1.INJECTABLE_METADATA, options, target);
11
- container_1.container.register(target, options);
12
- registry_1.registry.registerProvider(target);
7
+ Reflect.defineMetadata(INJECTABLE_METADATA, options, target);
8
+ container.register(target, options);
9
+ registry.registerProvider(target);
13
10
  };
14
11
  }
@@ -1,6 +1,6 @@
1
1
  import 'reflect-metadata';
2
2
  import type { ZodType } from 'zod';
3
- import { ParamType } from '../constants';
3
+ import { ParamType } from '../constants.js';
4
4
  export interface ParamMetadata {
5
5
  index: number;
6
6
  type: ParamType;