@riktajs/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +205 -0
- package/dist/core/application.d.ts +28 -0
- package/dist/core/application.d.ts.map +1 -0
- package/dist/core/application.js +321 -0
- package/dist/core/application.js.map +1 -0
- package/dist/core/constants.d.ts +70 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +77 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/container/container.d.ts +101 -0
- package/dist/core/container/container.d.ts.map +1 -0
- package/dist/core/container/container.js +327 -0
- package/dist/core/container/container.js.map +1 -0
- package/dist/core/container/index.d.ts +3 -0
- package/dist/core/container/index.d.ts.map +1 -0
- package/dist/core/container/index.js +19 -0
- package/dist/core/container/index.js.map +1 -0
- package/dist/core/container/injection-token.d.ts +58 -0
- package/dist/core/container/injection-token.d.ts.map +1 -0
- package/dist/core/container/injection-token.js +37 -0
- package/dist/core/container/injection-token.js.map +1 -0
- package/dist/core/decorators/autowired.decorator.d.ts +72 -0
- package/dist/core/decorators/autowired.decorator.d.ts.map +1 -0
- package/dist/core/decorators/autowired.decorator.js +143 -0
- package/dist/core/decorators/autowired.decorator.js.map +1 -0
- package/dist/core/decorators/controller.decorator.d.ts +33 -0
- package/dist/core/decorators/controller.decorator.d.ts.map +1 -0
- package/dist/core/decorators/controller.decorator.js +50 -0
- package/dist/core/decorators/controller.decorator.js.map +1 -0
- package/dist/core/decorators/index.d.ts +7 -0
- package/dist/core/decorators/index.d.ts.map +1 -0
- package/dist/core/decorators/index.js +24 -0
- package/dist/core/decorators/index.js.map +1 -0
- package/dist/core/decorators/injectable.decorator.d.ts +26 -0
- package/dist/core/decorators/injectable.decorator.d.ts.map +1 -0
- package/dist/core/decorators/injectable.decorator.js +40 -0
- package/dist/core/decorators/injectable.decorator.js.map +1 -0
- package/dist/core/decorators/param.decorator.d.ts +72 -0
- package/dist/core/decorators/param.decorator.d.ts.map +1 -0
- package/dist/core/decorators/param.decorator.js +88 -0
- package/dist/core/decorators/param.decorator.js.map +1 -0
- package/dist/core/decorators/provider.decorator.d.ts +64 -0
- package/dist/core/decorators/provider.decorator.d.ts.map +1 -0
- package/dist/core/decorators/provider.decorator.js +69 -0
- package/dist/core/decorators/provider.decorator.js.map +1 -0
- package/dist/core/decorators/route.decorator.d.ts +53 -0
- package/dist/core/decorators/route.decorator.d.ts.map +1 -0
- package/dist/core/decorators/route.decorator.js +85 -0
- package/dist/core/decorators/route.decorator.js.map +1 -0
- package/dist/core/discovery.d.ts +24 -0
- package/dist/core/discovery.d.ts.map +1 -0
- package/dist/core/discovery.js +168 -0
- package/dist/core/discovery.js.map +1 -0
- package/dist/core/exceptions/catch.decorator.d.ts +71 -0
- package/dist/core/exceptions/catch.decorator.d.ts.map +1 -0
- package/dist/core/exceptions/catch.decorator.js +77 -0
- package/dist/core/exceptions/catch.decorator.js.map +1 -0
- package/dist/core/exceptions/exception-filter.d.ts +134 -0
- package/dist/core/exceptions/exception-filter.d.ts.map +1 -0
- package/dist/core/exceptions/exception-filter.js +161 -0
- package/dist/core/exceptions/exception-filter.js.map +1 -0
- package/dist/core/exceptions/exceptions.d.ts +212 -0
- package/dist/core/exceptions/exceptions.d.ts.map +1 -0
- package/dist/core/exceptions/exceptions.js +275 -0
- package/dist/core/exceptions/exceptions.js.map +1 -0
- package/dist/core/exceptions/http-exception.d.ts +79 -0
- package/dist/core/exceptions/http-exception.d.ts.map +1 -0
- package/dist/core/exceptions/http-exception.js +106 -0
- package/dist/core/exceptions/http-exception.js.map +1 -0
- package/dist/core/exceptions/index.d.ts +5 -0
- package/dist/core/exceptions/index.d.ts.map +1 -0
- package/dist/core/exceptions/index.js +38 -0
- package/dist/core/exceptions/index.js.map +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +28 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lifecycle/event-bus.d.ts +96 -0
- package/dist/core/lifecycle/event-bus.d.ts.map +1 -0
- package/dist/core/lifecycle/event-bus.js +91 -0
- package/dist/core/lifecycle/event-bus.js.map +1 -0
- package/dist/core/lifecycle/index.d.ts +4 -0
- package/dist/core/lifecycle/index.d.ts.map +1 -0
- package/dist/core/lifecycle/index.js +21 -0
- package/dist/core/lifecycle/index.js.map +1 -0
- package/dist/core/lifecycle/interfaces.d.ts +106 -0
- package/dist/core/lifecycle/interfaces.d.ts.map +1 -0
- package/dist/core/lifecycle/interfaces.js +10 -0
- package/dist/core/lifecycle/interfaces.js.map +1 -0
- package/dist/core/lifecycle/on.decorator.d.ts +62 -0
- package/dist/core/lifecycle/on.decorator.d.ts.map +1 -0
- package/dist/core/lifecycle/on.decorator.js +65 -0
- package/dist/core/lifecycle/on.decorator.js.map +1 -0
- package/dist/core/registry.d.ts +64 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +91 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/router/router.d.ts +39 -0
- package/dist/core/router/router.d.ts.map +1 -0
- package/dist/core/router/router.js +150 -0
- package/dist/core/router/router.js.map +1 -0
- package/dist/core/types.d.ts +161 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +3 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { Token } from '../container/injection-token';
|
|
3
|
+
/**
|
|
4
|
+
* Metadata for autowired parameters/properties
|
|
5
|
+
*/
|
|
6
|
+
export interface AutowiredMetadata {
|
|
7
|
+
token: Token;
|
|
8
|
+
index?: number;
|
|
9
|
+
propertyKey?: string;
|
|
10
|
+
optional?: boolean;
|
|
11
|
+
}
|
|
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
|
+
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
|
+
export declare function Optional(): ParameterDecorator & PropertyDecorator;
|
|
72
|
+
//# sourceMappingURL=autowired.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autowired.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/autowired.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,kBAAkB,GAAG,iBAAiB,CAoD/E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,QAAQ,IAAI,kBAAkB,GAAG,iBAAiB,CAsDjE"}
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
/**
|
|
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
|
+
function Autowired(token) {
|
|
40
|
+
return (target, propertyKey, parameterIndex) => {
|
|
41
|
+
if (typeof parameterIndex === 'number') {
|
|
42
|
+
// Constructor parameter injection
|
|
43
|
+
const paramTypes = Reflect.getMetadata('design:paramtypes', target) ?? [];
|
|
44
|
+
const inferredType = paramTypes[parameterIndex];
|
|
45
|
+
const resolvedToken = token ?? inferredType;
|
|
46
|
+
if (!resolvedToken) {
|
|
47
|
+
throw new Error(`@Autowired() on constructor parameter ${parameterIndex} of ${target.name} ` +
|
|
48
|
+
`could not infer type. Please provide a token explicitly.`);
|
|
49
|
+
}
|
|
50
|
+
const existingInjects = Reflect.getMetadata(constants_1.INJECT_METADATA, target) ?? [];
|
|
51
|
+
existingInjects.push({
|
|
52
|
+
token: resolvedToken,
|
|
53
|
+
index: parameterIndex,
|
|
54
|
+
});
|
|
55
|
+
Reflect.defineMetadata(constants_1.INJECT_METADATA, existingInjects, target);
|
|
56
|
+
}
|
|
57
|
+
else if (propertyKey !== undefined) {
|
|
58
|
+
// Property injection
|
|
59
|
+
const inferredType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
60
|
+
const resolvedToken = token ?? inferredType;
|
|
61
|
+
if (!resolvedToken) {
|
|
62
|
+
throw new Error(`@Autowired() on ${target.constructor.name}.${String(propertyKey)} ` +
|
|
63
|
+
`could not infer type. Please provide a token explicitly.`);
|
|
64
|
+
}
|
|
65
|
+
const existingAutowires = Reflect.getMetadata(constants_1.AUTOWIRED_METADATA, target.constructor) ?? [];
|
|
66
|
+
existingAutowires.push({
|
|
67
|
+
token: resolvedToken,
|
|
68
|
+
propertyKey: String(propertyKey),
|
|
69
|
+
});
|
|
70
|
+
Reflect.defineMetadata(constants_1.AUTOWIRED_METADATA, existingAutowires, target.constructor);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
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
|
+
function Optional() {
|
|
101
|
+
return (target, propertyKey, parameterIndex) => {
|
|
102
|
+
if (typeof parameterIndex === 'number') {
|
|
103
|
+
// Constructor parameter
|
|
104
|
+
const existingInjects = Reflect.getMetadata(constants_1.INJECT_METADATA, target) ?? [];
|
|
105
|
+
let meta = existingInjects.find(m => m.index === parameterIndex);
|
|
106
|
+
if (meta) {
|
|
107
|
+
meta.optional = true;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const paramTypes = Reflect.getMetadata('design:paramtypes', target) ?? [];
|
|
111
|
+
const paramType = paramTypes[parameterIndex];
|
|
112
|
+
if (paramType) {
|
|
113
|
+
existingInjects.push({
|
|
114
|
+
token: paramType,
|
|
115
|
+
index: parameterIndex,
|
|
116
|
+
optional: true,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
Reflect.defineMetadata(constants_1.INJECT_METADATA, existingInjects, target);
|
|
121
|
+
}
|
|
122
|
+
else if (propertyKey !== undefined) {
|
|
123
|
+
// Property injection
|
|
124
|
+
const existingAutowires = Reflect.getMetadata(constants_1.AUTOWIRED_METADATA, target.constructor) ?? [];
|
|
125
|
+
let meta = existingAutowires.find(m => m.propertyKey === String(propertyKey));
|
|
126
|
+
if (meta) {
|
|
127
|
+
meta.optional = true;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const propType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
131
|
+
if (propType) {
|
|
132
|
+
existingAutowires.push({
|
|
133
|
+
token: propType,
|
|
134
|
+
propertyKey: String(propertyKey),
|
|
135
|
+
optional: true,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
Reflect.defineMetadata(constants_1.AUTOWIRED_METADATA, existingAutowires, target.constructor);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=autowired.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autowired.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/autowired.decorator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
/**
|
|
3
|
+
* Controller options
|
|
4
|
+
*/
|
|
5
|
+
export interface ControllerOptions {
|
|
6
|
+
/** Route prefix for all routes in this controller */
|
|
7
|
+
prefix?: string;
|
|
8
|
+
}
|
|
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
|
+
export declare function Controller(prefixOrOptions?: string | ControllerOptions): ClassDecorator;
|
|
33
|
+
//# sourceMappingURL=controller.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/controller.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAK1B;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,iBAAiB,GAAG,cAAc,CAuBvF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
/**
|
|
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
|
+
function Controller(prefixOrOptions) {
|
|
32
|
+
return (target) => {
|
|
33
|
+
const prefix = typeof prefixOrOptions === 'string'
|
|
34
|
+
? prefixOrOptions
|
|
35
|
+
: prefixOrOptions?.prefix ?? '';
|
|
36
|
+
// Normalize prefix (ensure it starts with / if not empty)
|
|
37
|
+
const normalizedPrefix = prefix
|
|
38
|
+
? (prefix.startsWith('/') ? prefix : `/${prefix}`)
|
|
39
|
+
: '';
|
|
40
|
+
// Store controller metadata
|
|
41
|
+
Reflect.defineMetadata(constants_1.CONTROLLER_METADATA, { prefix: normalizedPrefix }, target);
|
|
42
|
+
// Mark as injectable
|
|
43
|
+
Reflect.defineMetadata(constants_1.INJECTABLE_METADATA, { scope: 'singleton' }, target);
|
|
44
|
+
// Register in DI container
|
|
45
|
+
container_1.container.register(target, { scope: 'singleton' });
|
|
46
|
+
// Auto-register in global registry for discovery
|
|
47
|
+
registry_1.registry.registerController(target);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=controller.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/controller.decorator.ts"],"names":[],"mappings":";;AAoCA,gCAuBC;AA3DD,4BAA0B;AAC1B,4CAAwE;AACxE,sDAAmD;AACnD,0CAAuC;AAUvC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,UAAU,CAAC,eAA4C;IACrE,OAAO,CAAC,MAAgB,EAAE,EAAE;QAC1B,MAAM,MAAM,GAAG,OAAO,eAAe,KAAK,QAAQ;YAChD,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,eAAe,EAAE,MAAM,IAAI,EAAE,CAAC;QAElC,0DAA0D;QAC1D,MAAM,gBAAgB,GAAG,MAAM;YAC7B,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;YAClD,CAAC,CAAC,EAAE,CAAC;QAEP,4BAA4B;QAC5B,OAAO,CAAC,cAAc,CAAC,+BAAmB,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,MAAM,CAAC,CAAC;QAElF,qBAAqB;QACrB,OAAO,CAAC,cAAc,CAAC,+BAAmB,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,MAAM,CAAC,CAAC;QAE5E,2BAA2B;QAC3B,qBAAS,CAAC,QAAQ,CAAC,MAA6C,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;QAE1F,iDAAiD;QACjD,mBAAQ,CAAC,kBAAkB,CAAC,MAA6C,CAAC,CAAC;IAC7E,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
// Export all decorators
|
|
18
|
+
__exportStar(require("./injectable.decorator"), exports);
|
|
19
|
+
__exportStar(require("./controller.decorator"), exports);
|
|
20
|
+
__exportStar(require("./route.decorator"), exports);
|
|
21
|
+
__exportStar(require("./param.decorator"), exports);
|
|
22
|
+
__exportStar(require("./autowired.decorator"), exports);
|
|
23
|
+
__exportStar(require("./provider.decorator"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wBAAwB;AACxB,yDAAuC;AACvC,yDAAuC;AACvC,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AACtC,uDAAqC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { InjectableOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @Injectable() decorator
|
|
5
|
+
*
|
|
6
|
+
* Marks a class as injectable, allowing it to be managed by the DI container.
|
|
7
|
+
* Classes decorated with @Injectable() can be injected into other classes
|
|
8
|
+
* via constructor injection or @Autowired() property injection.
|
|
9
|
+
*
|
|
10
|
+
* The class is automatically registered in the global registry for lifecycle hooks.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* @Injectable()
|
|
15
|
+
* class UserService {
|
|
16
|
+
* getUsers() { return []; }
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* @Injectable()
|
|
20
|
+
* class UserController {
|
|
21
|
+
* constructor(private userService: UserService) {}
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function Injectable(options?: InjectableOptions): ClassDecorator;
|
|
26
|
+
//# sourceMappingURL=injectable.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectable.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/injectable.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAI7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,cAAc,CAW1E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* @Injectable() decorator
|
|
10
|
+
*
|
|
11
|
+
* Marks a class as injectable, allowing it to be managed by the DI container.
|
|
12
|
+
* Classes decorated with @Injectable() can be injected into other classes
|
|
13
|
+
* via constructor injection or @Autowired() property injection.
|
|
14
|
+
*
|
|
15
|
+
* The class is automatically registered in the global registry for lifecycle hooks.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* @Injectable()
|
|
20
|
+
* class UserService {
|
|
21
|
+
* getUsers() { return []; }
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @Injectable()
|
|
25
|
+
* class UserController {
|
|
26
|
+
* constructor(private userService: UserService) {}
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function Injectable(options = {}) {
|
|
31
|
+
return (target) => {
|
|
32
|
+
// Store injectable metadata
|
|
33
|
+
Reflect.defineMetadata(constants_1.INJECTABLE_METADATA, options, target);
|
|
34
|
+
// Register in DI container
|
|
35
|
+
container_1.container.register(target, options);
|
|
36
|
+
// Register in global registry for lifecycle hooks
|
|
37
|
+
registry_1.registry.registerProvider(target);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=injectable.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectable.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/injectable.decorator.ts"],"names":[],"mappings":";;AA4BA,gCAWC;AAvCD,4BAA0B;AAC1B,4CAAmD;AAEnD,sDAAmD;AACnD,0CAAuC;AAEvC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,UAAU,CAAC,UAA6B,EAAE;IACxD,OAAO,CAAC,MAAgB,EAAE,EAAE;QAC1B,4BAA4B;QAC5B,OAAO,CAAC,cAAc,CAAC,+BAAmB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAE7D,2BAA2B;QAC3B,qBAAS,CAAC,QAAQ,CAAC,MAA6C,EAAE,OAAO,CAAC,CAAC;QAE3E,kDAAkD;QAClD,mBAAQ,CAAC,gBAAgB,CAAC,MAA6C,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { ParamType } from '../constants';
|
|
3
|
+
/**
|
|
4
|
+
* Parameter metadata structure
|
|
5
|
+
*/
|
|
6
|
+
export interface ParamMetadata {
|
|
7
|
+
index: number;
|
|
8
|
+
type: ParamType;
|
|
9
|
+
key?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @Body() decorator - Injects the request body
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* @Post('/users')
|
|
17
|
+
* createUser(@Body({ schema: CreateUserDto }) data) { return data; }
|
|
18
|
+
*
|
|
19
|
+
* @Post('/users')
|
|
20
|
+
* createUser(@Body('name') name: string) { return { name }; }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const Body: (key?: string) => ParameterDecorator;
|
|
24
|
+
/**
|
|
25
|
+
* @Query() decorator - Injects query parameters
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* @Get('/users')
|
|
30
|
+
* getUsers(@Query('page') page: string) { return { page }; }
|
|
31
|
+
*
|
|
32
|
+
* @Get('/users')
|
|
33
|
+
* getUsers(@Query() query: Record<string, unknown>) { return query; }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const Query: (key?: string) => ParameterDecorator;
|
|
37
|
+
/**
|
|
38
|
+
* @Param() decorator - Injects route parameters
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* @Get('/users/:id')
|
|
43
|
+
* getUser(@Param('id') id: string) { return { id }; }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const Param: (key?: string) => ParameterDecorator;
|
|
47
|
+
/**
|
|
48
|
+
* @Headers() decorator - Injects request headers
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* @Get('/protected')
|
|
53
|
+
* getData(@Headers('authorization') auth: string) { return { auth }; }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare const Headers: (key?: string) => ParameterDecorator;
|
|
57
|
+
/**
|
|
58
|
+
* @Req() decorator - Injects the raw Fastify request object
|
|
59
|
+
*/
|
|
60
|
+
export declare const Req: (key?: string) => ParameterDecorator;
|
|
61
|
+
export declare const Request: (key?: string) => ParameterDecorator;
|
|
62
|
+
/**
|
|
63
|
+
* @Res() decorator - Injects the raw Fastify reply object
|
|
64
|
+
*/
|
|
65
|
+
export declare const Res: (key?: string) => ParameterDecorator;
|
|
66
|
+
export declare const Reply: (key?: string) => ParameterDecorator;
|
|
67
|
+
/**
|
|
68
|
+
* @Ctx() decorator - Injects the full route context
|
|
69
|
+
*/
|
|
70
|
+
export declare const Ctx: (key?: string) => ParameterDecorator;
|
|
71
|
+
export declare const Context: (key?: string) => ParameterDecorator;
|
|
72
|
+
//# sourceMappingURL=param.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"param.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/param.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAkB,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,SAAS,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AA2BD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI,SAjCD,MAAM,KAAG,kBAiC+B,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,KAAK,SA/CF,MAAM,KAAG,kBA+CiC,CAAC;AAE3D;;;;;;;;GAQG;AACH,eAAO,MAAM,KAAK,SA1DF,MAAM,KAAG,kBA0DiC,CAAC;AAE3D;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,SArEJ,MAAM,KAAG,kBAqEqC,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,GAAG,SA1EA,MAAM,KAAG,kBA0EiC,CAAC;AAC3D,eAAO,MAAM,OAAO,SA3EJ,MAAM,KAAG,kBA2EC,CAAC;AAE3B;;GAEG;AACH,eAAO,MAAM,GAAG,SAhFA,MAAM,KAAG,kBAgF+B,CAAC;AACzD,eAAO,MAAM,KAAK,SAjFF,MAAM,KAAG,kBAiFD,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,GAAG,SAtFA,MAAM,KAAG,kBAsFiC,CAAC;AAC3D,eAAO,MAAM,OAAO,SAvFJ,MAAM,KAAG,kBAuFC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Context = exports.Ctx = exports.Reply = exports.Res = exports.Request = exports.Req = exports.Headers = exports.Param = exports.Query = exports.Body = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a parameter decorator
|
|
8
|
+
*/
|
|
9
|
+
function createParamDecorator(type) {
|
|
10
|
+
return (key) => {
|
|
11
|
+
return (target, propertyKey, parameterIndex) => {
|
|
12
|
+
if (propertyKey === undefined)
|
|
13
|
+
return;
|
|
14
|
+
// Get existing params or initialize empty array
|
|
15
|
+
const existingParams = Reflect.getMetadata(constants_1.PARAM_METADATA, target.constructor, propertyKey) ?? [];
|
|
16
|
+
// Add this param
|
|
17
|
+
existingParams.push({
|
|
18
|
+
index: parameterIndex,
|
|
19
|
+
type,
|
|
20
|
+
key,
|
|
21
|
+
});
|
|
22
|
+
// Store updated params
|
|
23
|
+
Reflect.defineMetadata(constants_1.PARAM_METADATA, existingParams, target.constructor, propertyKey);
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @Body() decorator - Injects the request body
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* @Post('/users')
|
|
33
|
+
* createUser(@Body({ schema: CreateUserDto }) data) { return data; }
|
|
34
|
+
*
|
|
35
|
+
* @Post('/users')
|
|
36
|
+
* createUser(@Body('name') name: string) { return { name }; }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
exports.Body = createParamDecorator(constants_1.ParamType.BODY);
|
|
40
|
+
/**
|
|
41
|
+
* @Query() decorator - Injects query parameters
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* @Get('/users')
|
|
46
|
+
* getUsers(@Query('page') page: string) { return { page }; }
|
|
47
|
+
*
|
|
48
|
+
* @Get('/users')
|
|
49
|
+
* getUsers(@Query() query: Record<string, unknown>) { return query; }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
exports.Query = createParamDecorator(constants_1.ParamType.QUERY);
|
|
53
|
+
/**
|
|
54
|
+
* @Param() decorator - Injects route parameters
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* @Get('/users/:id')
|
|
59
|
+
* getUser(@Param('id') id: string) { return { id }; }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
exports.Param = createParamDecorator(constants_1.ParamType.PARAM);
|
|
63
|
+
/**
|
|
64
|
+
* @Headers() decorator - Injects request headers
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* @Get('/protected')
|
|
69
|
+
* getData(@Headers('authorization') auth: string) { return { auth }; }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
exports.Headers = createParamDecorator(constants_1.ParamType.HEADERS);
|
|
73
|
+
/**
|
|
74
|
+
* @Req() decorator - Injects the raw Fastify request object
|
|
75
|
+
*/
|
|
76
|
+
exports.Req = createParamDecorator(constants_1.ParamType.REQUEST);
|
|
77
|
+
exports.Request = exports.Req;
|
|
78
|
+
/**
|
|
79
|
+
* @Res() decorator - Injects the raw Fastify reply object
|
|
80
|
+
*/
|
|
81
|
+
exports.Res = createParamDecorator(constants_1.ParamType.REPLY);
|
|
82
|
+
exports.Reply = exports.Res;
|
|
83
|
+
/**
|
|
84
|
+
* @Ctx() decorator - Injects the full route context
|
|
85
|
+
*/
|
|
86
|
+
exports.Ctx = createParamDecorator(constants_1.ParamType.CONTEXT);
|
|
87
|
+
exports.Context = exports.Ctx;
|
|
88
|
+
//# sourceMappingURL=param.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"param.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/param.decorator.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,4CAAyD;AAWzD;;GAEG;AACH,SAAS,oBAAoB,CAAC,IAAe;IAC3C,OAAO,CAAC,GAAY,EAAsB,EAAE;QAC1C,OAAO,CAAC,MAAc,EAAE,WAAwC,EAAE,cAAsB,EAAE,EAAE;YAC1F,IAAI,WAAW,KAAK,SAAS;gBAAE,OAAO;YAEtC,gDAAgD;YAChD,MAAM,cAAc,GAClB,OAAO,CAAC,WAAW,CAAC,0BAAc,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;YAE7E,iBAAiB;YACjB,cAAc,CAAC,IAAI,CAAC;gBAClB,KAAK,EAAE,cAAc;gBACrB,IAAI;gBACJ,GAAG;aACJ,CAAC,CAAC;YAEH,uBAAuB;YACvB,OAAO,CAAC,cAAc,CAAC,0BAAc,EAAE,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAC1F,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACU,QAAA,IAAI,GAAG,oBAAoB,CAAC,qBAAS,CAAC,IAAI,CAAC,CAAC;AAEzD;;;;;;;;;;;GAWG;AACU,QAAA,KAAK,GAAG,oBAAoB,CAAC,qBAAS,CAAC,KAAK,CAAC,CAAC;AAE3D;;;;;;;;GAQG;AACU,QAAA,KAAK,GAAG,oBAAoB,CAAC,qBAAS,CAAC,KAAK,CAAC,CAAC;AAE3D;;;;;;;;GAQG;AACU,QAAA,OAAO,GAAG,oBAAoB,CAAC,qBAAS,CAAC,OAAO,CAAC,CAAC;AAE/D;;GAEG;AACU,QAAA,GAAG,GAAG,oBAAoB,CAAC,qBAAS,CAAC,OAAO,CAAC,CAAC;AAC9C,QAAA,OAAO,GAAG,WAAG,CAAC;AAE3B;;GAEG;AACU,QAAA,GAAG,GAAG,oBAAoB,CAAC,qBAAS,CAAC,KAAK,CAAC,CAAC;AAC5C,QAAA,KAAK,GAAG,WAAG,CAAC;AAEzB;;GAEG;AACU,QAAA,GAAG,GAAG,oBAAoB,CAAC,qBAAS,CAAC,OAAO,CAAC,CAAC;AAC9C,QAAA,OAAO,GAAG,WAAG,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { Token } from '../container/injection-token';
|
|
3
|
+
/**
|
|
4
|
+
* Provider metadata stored on the class
|
|
5
|
+
*/
|
|
6
|
+
export interface ProviderMetadata {
|
|
7
|
+
token: Token;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @Provider() decorator
|
|
11
|
+
*
|
|
12
|
+
* Marks a class as a custom provider that will be auto-discovered.
|
|
13
|
+
* The class must implement a `provide()` method that returns the value.
|
|
14
|
+
*
|
|
15
|
+
* Providers can inject dependencies via constructor or @Autowired properties,
|
|
16
|
+
* making them perfect for complex factory logic.
|
|
17
|
+
*
|
|
18
|
+
* @param token - The injection token this provider supplies
|
|
19
|
+
*
|
|
20
|
+
* @example Simple value provider:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const APP_CONFIG = new InjectionToken<AppConfig>('app.config');
|
|
23
|
+
*
|
|
24
|
+
* @Provider(APP_CONFIG)
|
|
25
|
+
* export class AppConfigProvider {
|
|
26
|
+
* provide(): AppConfig {
|
|
27
|
+
* return {
|
|
28
|
+
* name: 'My App',
|
|
29
|
+
* version: '1.0.0',
|
|
30
|
+
* };
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Provider with dependencies:
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const LOGGER = new InjectionToken<Logger>('logger');
|
|
38
|
+
*
|
|
39
|
+
* @Provider(LOGGER)
|
|
40
|
+
* export class LoggerProvider {
|
|
41
|
+
* constructor(@Autowired(APP_CONFIG) private config: AppConfig) {}
|
|
42
|
+
*
|
|
43
|
+
* provide(): Logger {
|
|
44
|
+
* return createLogger({
|
|
45
|
+
* appName: this.config.name,
|
|
46
|
+
* level: this.config.debug ? 'debug' : 'info',
|
|
47
|
+
* });
|
|
48
|
+
* }
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example Async provider:
|
|
53
|
+
* ```typescript
|
|
54
|
+
* @Provider(DATABASE)
|
|
55
|
+
* export class DatabaseProvider {
|
|
56
|
+
* async provide(): Promise<Database> {
|
|
57
|
+
* const db = await connectToDatabase();
|
|
58
|
+
* return db;
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function Provider(token: Token): ClassDecorator;
|
|
64
|
+
//# sourceMappingURL=provider.decorator.d.ts.map
|