@albertoielpo/ielpify 0.1.0 → 0.2.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/dist/cjs/decorators/injectable.decorator.d.ts +39 -0
- package/dist/cjs/decorators/injectable.decorator.d.ts.map +1 -1
- package/dist/cjs/decorators/injectable.decorator.js +46 -3
- package/dist/cjs/decorators/injectable.decorator.js.map +1 -1
- package/dist/cjs/decorators/route.decorator.d.ts +42 -0
- package/dist/cjs/decorators/route.decorator.d.ts.map +1 -1
- package/dist/cjs/decorators/route.decorator.js +51 -0
- package/dist/cjs/decorators/route.decorator.js.map +1 -1
- package/dist/cjs/decorators/timeout.decorator.d.ts +27 -0
- package/dist/cjs/decorators/timeout.decorator.d.ts.map +1 -0
- package/dist/cjs/decorators/timeout.decorator.js +45 -0
- package/dist/cjs/decorators/timeout.decorator.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/decorators/injectable.decorator.d.ts +39 -0
- package/dist/esm/decorators/injectable.decorator.d.ts.map +1 -1
- package/dist/esm/decorators/injectable.decorator.js +46 -3
- package/dist/esm/decorators/injectable.decorator.js.map +1 -1
- package/dist/esm/decorators/route.decorator.d.ts +42 -0
- package/dist/esm/decorators/route.decorator.d.ts.map +1 -1
- package/dist/esm/decorators/route.decorator.js +51 -0
- package/dist/esm/decorators/route.decorator.js.map +1 -1
- package/dist/esm/decorators/timeout.decorator.d.ts +27 -0
- package/dist/esm/decorators/timeout.decorator.d.ts.map +1 -0
- package/dist/esm/decorators/timeout.decorator.js +45 -0
- package/dist/esm/decorators/timeout.decorator.js.map +1 -0
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +8 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks a class as a singleton service for dependency injection.
|
|
3
|
+
* Classes decorated with @Injectable() will have a single instance
|
|
4
|
+
* shared across all consumers.
|
|
5
|
+
* @returns A class decorator
|
|
6
|
+
*/
|
|
1
7
|
export declare function Injectable(): ClassDecorator;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a class is decorated with @Injectable().
|
|
10
|
+
* @param target - The class to check
|
|
11
|
+
* @returns True if the class is injectable, false otherwise
|
|
12
|
+
*/
|
|
2
13
|
export declare function isInjectable(target: new () => object): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Registers a service in the DI container.
|
|
16
|
+
* If the service is not already registered, it will be instantiated.
|
|
17
|
+
* @param serviceClass - The service class to register
|
|
18
|
+
*/
|
|
3
19
|
export declare function registerService<T extends object>(serviceClass: new () => T): void;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a service from the DI container.
|
|
22
|
+
* Creates a new instance if the service is not already registered.
|
|
23
|
+
* @param serviceClass - The service class to resolve
|
|
24
|
+
* @returns The singleton instance of the service
|
|
25
|
+
* @throws Error if the class is not decorated with @Injectable()
|
|
26
|
+
*/
|
|
4
27
|
export declare function resolveService<T extends object>(serviceClass: new () => T): T;
|
|
28
|
+
/**
|
|
29
|
+
* Marks a constructor parameter for dependency injection.
|
|
30
|
+
* @param serviceClass - The service class to inject
|
|
31
|
+
* @returns A parameter decorator
|
|
32
|
+
*/
|
|
5
33
|
export declare function Inject(serviceClass: new () => object): ParameterDecorator;
|
|
34
|
+
/**
|
|
35
|
+
* Creates an instance of a class with its dependencies automatically injected.
|
|
36
|
+
* @param targetClass - The class to instantiate
|
|
37
|
+
* @returns A new instance with all @Inject() dependencies resolved
|
|
38
|
+
*/
|
|
6
39
|
export declare function createWithInjection<T extends object>(targetClass: new (...args: any[]) => T): T;
|
|
40
|
+
/**
|
|
41
|
+
* Returns all instances currently stored in the DI container.
|
|
42
|
+
* Useful for applying lifecycle operations to all services.
|
|
43
|
+
* @returns An array of all registered service instances
|
|
44
|
+
*/
|
|
45
|
+
export declare function getContainerInstances(): object[];
|
|
7
46
|
//# sourceMappingURL=injectable.decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectable.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"injectable.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,cAAc,CAI3C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,MAAM,GAAG,OAAO,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAC5C,YAAY,EAAE,UAAU,CAAC,GAC1B,IAAI,CAEN;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAU7E;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,YAAY,EAAE,UAAU,MAAM,GAAG,kBAAkB,CAOzE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EAChD,WAAW,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GACvC,CAAC,CAWH;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAEhD"}
|
|
@@ -6,21 +6,45 @@ exports.registerService = registerService;
|
|
|
6
6
|
exports.resolveService = resolveService;
|
|
7
7
|
exports.Inject = Inject;
|
|
8
8
|
exports.createWithInjection = createWithInjection;
|
|
9
|
+
exports.getContainerInstances = getContainerInstances;
|
|
10
|
+
// DI Container - stores singleton instances
|
|
9
11
|
const container = new Map();
|
|
12
|
+
// Metadata key for marking classes as injectable
|
|
10
13
|
const INJECTABLE_METADATA = Symbol("injectable");
|
|
14
|
+
/**
|
|
15
|
+
* Marks a class as a singleton service for dependency injection.
|
|
16
|
+
* Classes decorated with @Injectable() will have a single instance
|
|
17
|
+
* shared across all consumers.
|
|
18
|
+
* @returns A class decorator
|
|
19
|
+
*/
|
|
11
20
|
function Injectable() {
|
|
12
21
|
return (target) => {
|
|
13
22
|
Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
|
|
14
23
|
};
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a class is decorated with @Injectable().
|
|
27
|
+
* @param target - The class to check
|
|
28
|
+
* @returns True if the class is injectable, false otherwise
|
|
29
|
+
*/
|
|
16
30
|
function isInjectable(target) {
|
|
17
31
|
return Reflect.getMetadata(INJECTABLE_METADATA, target) === true;
|
|
18
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Registers a service in the DI container.
|
|
35
|
+
* If the service is not already registered, it will be instantiated.
|
|
36
|
+
* @param serviceClass - The service class to register
|
|
37
|
+
*/
|
|
19
38
|
function registerService(serviceClass) {
|
|
20
|
-
|
|
21
|
-
container.set(serviceClass, new serviceClass());
|
|
22
|
-
}
|
|
39
|
+
resolveService(serviceClass);
|
|
23
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Resolves a service from the DI container.
|
|
43
|
+
* Creates a new instance if the service is not already registered.
|
|
44
|
+
* @param serviceClass - The service class to resolve
|
|
45
|
+
* @returns The singleton instance of the service
|
|
46
|
+
* @throws Error if the class is not decorated with @Injectable()
|
|
47
|
+
*/
|
|
24
48
|
function resolveService(serviceClass) {
|
|
25
49
|
if (!isInjectable(serviceClass)) {
|
|
26
50
|
throw new Error(`${serviceClass.name} is not injectable. Add @Injectable() decorator.`);
|
|
@@ -30,6 +54,11 @@ function resolveService(serviceClass) {
|
|
|
30
54
|
}
|
|
31
55
|
return container.get(serviceClass);
|
|
32
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Marks a constructor parameter for dependency injection.
|
|
59
|
+
* @param serviceClass - The service class to inject
|
|
60
|
+
* @returns A parameter decorator
|
|
61
|
+
*/
|
|
33
62
|
function Inject(serviceClass) {
|
|
34
63
|
return (target, propertyKey, parameterIndex) => {
|
|
35
64
|
const existingInjections = Reflect.getMetadata("injections", target) || new Map();
|
|
@@ -37,12 +66,26 @@ function Inject(serviceClass) {
|
|
|
37
66
|
Reflect.defineMetadata("injections", existingInjections, target);
|
|
38
67
|
};
|
|
39
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates an instance of a class with its dependencies automatically injected.
|
|
71
|
+
* @param targetClass - The class to instantiate
|
|
72
|
+
* @returns A new instance with all @Inject() dependencies resolved
|
|
73
|
+
*/
|
|
40
74
|
function createWithInjection(targetClass) {
|
|
41
75
|
const injections = Reflect.getMetadata("injections", targetClass) || new Map();
|
|
76
|
+
// Build constructor arguments from injections
|
|
42
77
|
const args = [];
|
|
43
78
|
injections.forEach((serviceClass, index) => {
|
|
44
79
|
args[index] = resolveService(serviceClass);
|
|
45
80
|
});
|
|
46
81
|
return new targetClass(...args);
|
|
47
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns all instances currently stored in the DI container.
|
|
85
|
+
* Useful for applying lifecycle operations to all services.
|
|
86
|
+
* @returns An array of all registered service instances
|
|
87
|
+
*/
|
|
88
|
+
function getContainerInstances() {
|
|
89
|
+
return Array.from(container.values());
|
|
90
|
+
}
|
|
48
91
|
//# sourceMappingURL=injectable.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectable.decorator.js","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"injectable.decorator.js","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":";;AAYA,gCAIC;AAOD,oCAEC;AAOD,0CAIC;AASD,wCAUC;AAOD,wBAOC;AAOD,kDAaC;AAOD,sDAEC;AAlGD,4CAA4C;AAC5C,MAAM,S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AY,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAC/B,WAAsC;IAEtC,MAAM,UAAU,GACZ,OAAO,CAAC,WAAW,CAAC,YAAY,EAAE,WAAW,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;IAEhE,8CAA8C;IAC9C,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,UAAU,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE;QACvC,IAAI,CAAC,KAAK,CAAC,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB;IACjC,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -1,11 +1,53 @@
|
|
|
1
1
|
import { FastifyInstance } from "fastify";
|
|
2
|
+
/**
|
|
3
|
+
* Marks a class as a controller with an optional route prefix.
|
|
4
|
+
* @param prefix - The base path prefix for all routes in this controller
|
|
5
|
+
* @returns A class decorator
|
|
6
|
+
*/
|
|
2
7
|
export declare function Controller(prefix?: string): ClassDecorator;
|
|
8
|
+
/**
|
|
9
|
+
* Marks a method as a GET route handler.
|
|
10
|
+
* @param path - The route path (optional)
|
|
11
|
+
* @returns A method decorator
|
|
12
|
+
*/
|
|
3
13
|
export declare const Get: (path?: string) => MethodDecorator;
|
|
14
|
+
/**
|
|
15
|
+
* Marks a method as a POST route handler.
|
|
16
|
+
* @param path - The route path (optional)
|
|
17
|
+
* @returns A method decorator
|
|
18
|
+
*/
|
|
4
19
|
export declare const Post: (path?: string) => MethodDecorator;
|
|
20
|
+
/**
|
|
21
|
+
* Marks a method as a PUT route handler.
|
|
22
|
+
* @param path - The route path (optional)
|
|
23
|
+
* @returns A method decorator
|
|
24
|
+
*/
|
|
5
25
|
export declare const Put: (path?: string) => MethodDecorator;
|
|
26
|
+
/**
|
|
27
|
+
* Marks a method as a DELETE route handler.
|
|
28
|
+
* @param path - The route path (optional)
|
|
29
|
+
* @returns A method decorator
|
|
30
|
+
*/
|
|
6
31
|
export declare const Delete: (path?: string) => MethodDecorator;
|
|
32
|
+
/**
|
|
33
|
+
* Marks a method as a PATCH route handler.
|
|
34
|
+
* @param path - The route path (optional)
|
|
35
|
+
* @returns A method decorator
|
|
36
|
+
*/
|
|
7
37
|
export declare const Patch: (path?: string) => MethodDecorator;
|
|
8
38
|
type ControllerClass = new (...args: any[]) => object;
|
|
39
|
+
/**
|
|
40
|
+
* Registers a controller with a Fastify instance.
|
|
41
|
+
* Creates the controller with dependency injection and sets up all routes.
|
|
42
|
+
* @param fastify - The Fastify instance
|
|
43
|
+
* @param controllerClass - The controller class to register
|
|
44
|
+
*/
|
|
9
45
|
export declare function registerController(fastify: FastifyInstance, controllerClass: ControllerClass): void;
|
|
46
|
+
/**
|
|
47
|
+
* Returns all registered controller instances.
|
|
48
|
+
* Useful for applying lifecycle operations to all controllers.
|
|
49
|
+
* @returns An array of all registered controller instances
|
|
50
|
+
*/
|
|
51
|
+
export declare function getControllerInstances(): object[];
|
|
10
52
|
export {};
|
|
11
53
|
//# sourceMappingURL=route.decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/route.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"route.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/route.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAuBxE;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,GAAE,MAAW,GAAG,cAAc,CAW9D;AAyBD;;;;GAIG;AACH,eAAO,MAAM,GAAG,UA1BE,MAAM,KAAQ,eA0Be,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,IAAI,UAjCC,MAAM,KAAQ,eAiCiB,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,GAAG,UAxCE,MAAM,KAAQ,eAwCe,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,MAAM,UA/CD,MAAM,KAAQ,eA+CqB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,KAAK,UAtDA,MAAM,KAAQ,eAsDmB,CAAC;AAGpD,KAAK,eAAe,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;AAKtD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,eAAe,EACxB,eAAe,EAAE,eAAe,GACjC,IAAI,CAgBN;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAEjD"}
|
|
@@ -3,14 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
|
|
4
4
|
exports.Controller = Controller;
|
|
5
5
|
exports.registerController = registerController;
|
|
6
|
+
exports.getControllerInstances = getControllerInstances;
|
|
6
7
|
const injectable_decorator_1 = require("./injectable.decorator");
|
|
8
|
+
// Metadata keys
|
|
7
9
|
const ROUTES_METADATA = Symbol("routes");
|
|
8
10
|
const CONTROLLER_PREFIX = Symbol("controller_prefix");
|
|
11
|
+
// Normalize path to ensure it starts with "/"
|
|
9
12
|
function normalizePath(path) {
|
|
10
13
|
if (!path)
|
|
11
14
|
return "";
|
|
12
15
|
return path.startsWith("/") ? path : `/${path}`;
|
|
13
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Marks a class as a controller with an optional route prefix.
|
|
19
|
+
* @param prefix - The base path prefix for all routes in this controller
|
|
20
|
+
* @returns A class decorator
|
|
21
|
+
*/
|
|
14
22
|
function Controller(prefix = "") {
|
|
15
23
|
return (target) => {
|
|
16
24
|
Reflect.defineMetadata(CONTROLLER_PREFIX, normalizePath(prefix), target);
|
|
@@ -19,6 +27,7 @@ function Controller(prefix = "") {
|
|
|
19
27
|
}
|
|
20
28
|
};
|
|
21
29
|
}
|
|
30
|
+
// Factory for HTTP method decorators
|
|
22
31
|
function createMethodDecorator(method) {
|
|
23
32
|
return (path = "") => {
|
|
24
33
|
return (target, propertyKey) => {
|
|
@@ -35,13 +44,47 @@ function createMethodDecorator(method) {
|
|
|
35
44
|
};
|
|
36
45
|
};
|
|
37
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Marks a method as a GET route handler.
|
|
49
|
+
* @param path - The route path (optional)
|
|
50
|
+
* @returns A method decorator
|
|
51
|
+
*/
|
|
38
52
|
exports.Get = createMethodDecorator("get");
|
|
53
|
+
/**
|
|
54
|
+
* Marks a method as a POST route handler.
|
|
55
|
+
* @param path - The route path (optional)
|
|
56
|
+
* @returns A method decorator
|
|
57
|
+
*/
|
|
39
58
|
exports.Post = createMethodDecorator("post");
|
|
59
|
+
/**
|
|
60
|
+
* Marks a method as a PUT route handler.
|
|
61
|
+
* @param path - The route path (optional)
|
|
62
|
+
* @returns A method decorator
|
|
63
|
+
*/
|
|
40
64
|
exports.Put = createMethodDecorator("put");
|
|
65
|
+
/**
|
|
66
|
+
* Marks a method as a DELETE route handler.
|
|
67
|
+
* @param path - The route path (optional)
|
|
68
|
+
* @returns A method decorator
|
|
69
|
+
*/
|
|
41
70
|
exports.Delete = createMethodDecorator("delete");
|
|
71
|
+
/**
|
|
72
|
+
* Marks a method as a PATCH route handler.
|
|
73
|
+
* @param path - The route path (optional)
|
|
74
|
+
* @returns A method decorator
|
|
75
|
+
*/
|
|
42
76
|
exports.Patch = createMethodDecorator("patch");
|
|
77
|
+
// Store registered controller instances
|
|
78
|
+
const controllerInstances = [];
|
|
79
|
+
/**
|
|
80
|
+
* Registers a controller with a Fastify instance.
|
|
81
|
+
* Creates the controller with dependency injection and sets up all routes.
|
|
82
|
+
* @param fastify - The Fastify instance
|
|
83
|
+
* @param controllerClass - The controller class to register
|
|
84
|
+
*/
|
|
43
85
|
function registerController(fastify, controllerClass) {
|
|
44
86
|
const controller = (0, injectable_decorator_1.createWithInjection)(controllerClass);
|
|
87
|
+
controllerInstances.push(controller);
|
|
45
88
|
const prefix = Reflect.getMetadata(CONTROLLER_PREFIX, controllerClass) || "";
|
|
46
89
|
const routes = Reflect.getMetadata(ROUTES_METADATA, controllerClass) || [];
|
|
47
90
|
for (const route of routes) {
|
|
@@ -50,4 +93,12 @@ function registerController(fastify, controllerClass) {
|
|
|
50
93
|
fastify[route.method](fullPath, handler);
|
|
51
94
|
}
|
|
52
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns all registered controller instances.
|
|
98
|
+
* Useful for applying lifecycle operations to all controllers.
|
|
99
|
+
* @returns An array of all registered controller instances
|
|
100
|
+
*/
|
|
101
|
+
function getControllerInstances() {
|
|
102
|
+
return controllerInstances;
|
|
103
|
+
}
|
|
53
104
|
//# sourceMappingURL=route.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.decorator.js","sourceRoot":"","sources":["../../../src/decorators/route.decorator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"route.decorator.js","sourceRoot":"","sources":["../../../src/decorators/route.decorator.ts"],"names":[],"mappings":";;;AA4BA,gCAWC;AAwED,gDAmBC;AAOD,wDAEC;AA1ID,iEAA6D;AAE7D,gBAAgB;AAChB,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACzC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAKtD,8CAA8C;AAC9C,SAAS,aAAa,CAAC,IAAY;IAC/B,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,OAAO,IAAI,CAAC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|
|
8
|
+
* Number of times to execute the method.
|
|
9
|
+
* Use -1 for infinite executions.
|
|
10
|
+
* @default 1
|
|
11
|
+
*/
|
|
12
|
+
times?: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Schedules a method to run repeatedly with a delay.
|
|
16
|
+
* The method will be executed after the initial delay, then repeat based on the times option.
|
|
17
|
+
* @param options - Configuration options for the timeout
|
|
18
|
+
* @returns A method decorator
|
|
19
|
+
*/
|
|
20
|
+
export declare function Timeout(options: TimeoutOptions): MethodDecorator;
|
|
21
|
+
/**
|
|
22
|
+
* Starts all @Timeout decorated methods on an instance.
|
|
23
|
+
* Call this after instantiating a class to begin scheduled executions.
|
|
24
|
+
* @param instance - The object instance containing @Timeout decorated methods
|
|
25
|
+
*/
|
|
26
|
+
export declare function startTimeouts(instance: object): void;
|
|
27
|
+
//# sourceMappingURL=timeout.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/timeout.decorator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IACzB,oDAAoD;IACpD,EAAE,EAAE,MAAM,CAAC;IACX;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AASF;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,eAAe,CAQhE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAwBpD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Timeout = Timeout;
|
|
4
|
+
exports.startTimeouts = startTimeouts;
|
|
5
|
+
const TIMEOUT_METADATA = Symbol("timeout");
|
|
6
|
+
/**
|
|
7
|
+
* Schedules a method to run repeatedly with a delay.
|
|
8
|
+
* The method will be executed after the initial delay, then repeat based on the times option.
|
|
9
|
+
* @param options - Configuration options for the timeout
|
|
10
|
+
* @returns A method decorator
|
|
11
|
+
*/
|
|
12
|
+
function Timeout(options) {
|
|
13
|
+
return (target, propertyKey, descriptor) => {
|
|
14
|
+
const existingTimeouts = Reflect.getMetadata(TIMEOUT_METADATA, target.constructor) || [];
|
|
15
|
+
existingTimeouts.push({ propertyKey, options });
|
|
16
|
+
Reflect.defineMetadata(TIMEOUT_METADATA, existingTimeouts, target.constructor);
|
|
17
|
+
return descriptor;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Starts all @Timeout decorated methods on an instance.
|
|
22
|
+
* Call this after instantiating a class to begin scheduled executions.
|
|
23
|
+
* @param instance - The object instance containing @Timeout decorated methods
|
|
24
|
+
*/
|
|
25
|
+
function startTimeouts(instance) {
|
|
26
|
+
const timeouts = Reflect.getMetadata(TIMEOUT_METADATA, instance.constructor) || [];
|
|
27
|
+
for (const { propertyKey, options } of timeouts) {
|
|
28
|
+
const method = instance[propertyKey];
|
|
29
|
+
if (typeof method === "function") {
|
|
30
|
+
const times = options.times ?? 1;
|
|
31
|
+
let executionCount = 0;
|
|
32
|
+
const execute = () => {
|
|
33
|
+
if (times === -1 || executionCount < times) {
|
|
34
|
+
executionCount++;
|
|
35
|
+
method.call(instance);
|
|
36
|
+
if (times === -1 || executionCount < times) {
|
|
37
|
+
setTimeout(execute, options.ms);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
setTimeout(execute, options.ms);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=timeout.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.decorator.js","sourceRoot":"","sources":["../../../src/decorators/timeout.decorator.ts"],"names":[],"mappings":";;AA2BA,0BAQC;AAOD,sCAwBC;AApDD,MAAM,gBAAg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ACpC,CAAC;gBACL,CAAC;YACL,CAAC,CAAC;YAEF,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QACpC,CAAC;IACL,CAAC;AACL,CAAC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
export { createWithInjection, Inject, Injectable, isInjectable, registerService, resolveService } from "./decorators/injectable.decorator.js";
|
|
3
|
-
export {
|
|
2
|
+
export { createWithInjection, getContainerInstances, Inject, Injectable, isInjectable, registerService, resolveService } from "./decorators/injectable.decorator.js";
|
|
3
|
+
export { startTimeouts, Timeout, TimeoutOptions } from "./decorators/timeout.decorator.js";
|
|
4
|
+
export { Controller, Delete, Get, getControllerInstances, Patch, Post, Put, registerController } from "./decorators/route.decorator.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAG1B,OAAO,EACH,mBAAmB,EACnB,MAAM,EACN,UAAU,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACjB,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAG1B,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EACrB,MAAM,EACN,UAAU,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACjB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACH,aAAa,EACb,OAAO,EACP,cAAc,EACjB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EACH,UAAU,EACV,MAAM,EACN,GAAG,EACH,sBAAsB,EACtB,KAAK,EACL,IAAI,EACJ,GAAG,EACH,kBAAkB,EACrB,MAAM,iCAAiC,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerController = exports.Put = exports.Post = exports.Patch = exports.Get = exports.Delete = exports.Controller = exports.resolveService = exports.registerService = exports.isInjectable = exports.Injectable = exports.Inject = exports.createWithInjection = void 0;
|
|
3
|
+
exports.registerController = exports.Put = exports.Post = exports.Patch = exports.getControllerInstances = exports.Get = exports.Delete = exports.Controller = exports.Timeout = exports.startTimeouts = exports.resolveService = exports.registerService = exports.isInjectable = exports.Injectable = exports.Inject = exports.getContainerInstances = exports.createWithInjection = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
|
+
// Dependency Injection
|
|
5
6
|
var injectable_decorator_js_1 = require("./decorators/injectable.decorator.js");
|
|
6
7
|
Object.defineProperty(exports, "createWithInjection", { enumerable: true, get: function () { return injectable_decorator_js_1.createWithInjection; } });
|
|
8
|
+
Object.defineProperty(exports, "getContainerInstances", { enumerable: true, get: function () { return injectable_decorator_js_1.getContainerInstances; } });
|
|
7
9
|
Object.defineProperty(exports, "Inject", { enumerable: true, get: function () { return injectable_decorator_js_1.Inject; } });
|
|
8
10
|
Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return injectable_decorator_js_1.Injectable; } });
|
|
9
11
|
Object.defineProperty(exports, "isInjectable", { enumerable: true, get: function () { return injectable_decorator_js_1.isInjectable; } });
|
|
10
12
|
Object.defineProperty(exports, "registerService", { enumerable: true, get: function () { return injectable_decorator_js_1.registerService; } });
|
|
11
13
|
Object.defineProperty(exports, "resolveService", { enumerable: true, get: function () { return injectable_decorator_js_1.resolveService; } });
|
|
14
|
+
var timeout_decorator_js_1 = require("./decorators/timeout.decorator.js");
|
|
15
|
+
Object.defineProperty(exports, "startTimeouts", { enumerable: true, get: function () { return timeout_decorator_js_1.startTimeouts; } });
|
|
16
|
+
Object.defineProperty(exports, "Timeout", { enumerable: true, get: function () { return timeout_decorator_js_1.Timeout; } });
|
|
17
|
+
// Routing
|
|
12
18
|
var route_decorator_js_1 = require("./decorators/route.decorator.js");
|
|
13
19
|
Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return route_decorator_js_1.Controller; } });
|
|
14
20
|
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return route_decorator_js_1.Delete; } });
|
|
15
21
|
Object.defineProperty(exports, "Get", { enumerable: true, get: function () { return route_decorator_js_1.Get; } });
|
|
22
|
+
Object.defineProperty(exports, "getControllerInstances", { enumerable: true, get: function () { return route_decorator_js_1.getControllerInstances; } });
|
|
16
23
|
Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return route_decorator_js_1.Patch; } });
|
|
17
24
|
Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return route_decorator_js_1.Post; } });
|
|
18
25
|
Object.defineProperty(exports, "Put", { enumerable: true, get: function () { return route_decorator_js_1.Put; } });
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAE1B,uBAAuB;AACvB,gFAQ8C;AAP1C,8HAAA,mBAAmB,OAAA;AACnB,gIAAA,qBAAqB,OAAA;AACrB,iHAAA,MAAM,OAAA;AACN,qHAAA,UAAU,OAAA;AACV,uHAAA,YAAY,OAAA;AACZ,0HAAA,eAAe,OAAA;AACf,yHAAA,cAAc,OAAA;AAGlB,0EAI2C;AAHvC,qHAAA,aAAa,OAAA;AACb,+GAAA,OAAO,OAAA;AAIX,UAAU;AACV,sEASyC;AARrC,gHAAA,UAAU,OAAA;AACV,4GAAA,MAAM,OAAA;AACN,yGAAA,GAAG,OAAA;AACH,4HAAA,sBAAsB,OAAA;AACtB,2GAAA,KAAK,OAAA;AACL,0GAAA,IAAI,OAAA;AACJ,yGAAA,GAAG,OAAA;AACH,wHAAA,kBAAkB,OAAA"}
|
|
@@ -1,7 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks a class as a singleton service for dependency injection.
|
|
3
|
+
* Classes decorated with @Injectable() will have a single instance
|
|
4
|
+
* shared across all consumers.
|
|
5
|
+
* @returns A class decorator
|
|
6
|
+
*/
|
|
1
7
|
export declare function Injectable(): ClassDecorator;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a class is decorated with @Injectable().
|
|
10
|
+
* @param target - The class to check
|
|
11
|
+
* @returns True if the class is injectable, false otherwise
|
|
12
|
+
*/
|
|
2
13
|
export declare function isInjectable(target: new () => object): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Registers a service in the DI container.
|
|
16
|
+
* If the service is not already registered, it will be instantiated.
|
|
17
|
+
* @param serviceClass - The service class to register
|
|
18
|
+
*/
|
|
3
19
|
export declare function registerService<T extends object>(serviceClass: new () => T): void;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a service from the DI container.
|
|
22
|
+
* Creates a new instance if the service is not already registered.
|
|
23
|
+
* @param serviceClass - The service class to resolve
|
|
24
|
+
* @returns The singleton instance of the service
|
|
25
|
+
* @throws Error if the class is not decorated with @Injectable()
|
|
26
|
+
*/
|
|
4
27
|
export declare function resolveService<T extends object>(serviceClass: new () => T): T;
|
|
28
|
+
/**
|
|
29
|
+
* Marks a constructor parameter for dependency injection.
|
|
30
|
+
* @param serviceClass - The service class to inject
|
|
31
|
+
* @returns A parameter decorator
|
|
32
|
+
*/
|
|
5
33
|
export declare function Inject(serviceClass: new () => object): ParameterDecorator;
|
|
34
|
+
/**
|
|
35
|
+
* Creates an instance of a class with its dependencies automatically injected.
|
|
36
|
+
* @param targetClass - The class to instantiate
|
|
37
|
+
* @returns A new instance with all @Inject() dependencies resolved
|
|
38
|
+
*/
|
|
6
39
|
export declare function createWithInjection<T extends object>(targetClass: new (...args: any[]) => T): T;
|
|
40
|
+
/**
|
|
41
|
+
* Returns all instances currently stored in the DI container.
|
|
42
|
+
* Useful for applying lifecycle operations to all services.
|
|
43
|
+
* @returns An array of all registered service instances
|
|
44
|
+
*/
|
|
45
|
+
export declare function getContainerInstances(): object[];
|
|
7
46
|
//# sourceMappingURL=injectable.decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectable.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"injectable.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,cAAc,CAI3C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,MAAM,GAAG,OAAO,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAC5C,YAAY,EAAE,UAAU,CAAC,GAC1B,IAAI,CAEN;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAU7E;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,YAAY,EAAE,UAAU,MAAM,GAAG,kBAAkB,CAOzE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EAChD,WAAW,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GACvC,CAAC,CAWH;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAEhD"}
|
|
@@ -6,21 +6,45 @@ exports.registerService = registerService;
|
|
|
6
6
|
exports.resolveService = resolveService;
|
|
7
7
|
exports.Inject = Inject;
|
|
8
8
|
exports.createWithInjection = createWithInjection;
|
|
9
|
+
exports.getContainerInstances = getContainerInstances;
|
|
10
|
+
// DI Container - stores singleton instances
|
|
9
11
|
const container = new Map();
|
|
12
|
+
// Metadata key for marking classes as injectable
|
|
10
13
|
const INJECTABLE_METADATA = Symbol("injectable");
|
|
14
|
+
/**
|
|
15
|
+
* Marks a class as a singleton service for dependency injection.
|
|
16
|
+
* Classes decorated with @Injectable() will have a single instance
|
|
17
|
+
* shared across all consumers.
|
|
18
|
+
* @returns A class decorator
|
|
19
|
+
*/
|
|
11
20
|
function Injectable() {
|
|
12
21
|
return (target) => {
|
|
13
22
|
Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
|
|
14
23
|
};
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a class is decorated with @Injectable().
|
|
27
|
+
* @param target - The class to check
|
|
28
|
+
* @returns True if the class is injectable, false otherwise
|
|
29
|
+
*/
|
|
16
30
|
function isInjectable(target) {
|
|
17
31
|
return Reflect.getMetadata(INJECTABLE_METADATA, target) === true;
|
|
18
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Registers a service in the DI container.
|
|
35
|
+
* If the service is not already registered, it will be instantiated.
|
|
36
|
+
* @param serviceClass - The service class to register
|
|
37
|
+
*/
|
|
19
38
|
function registerService(serviceClass) {
|
|
20
|
-
|
|
21
|
-
container.set(serviceClass, new serviceClass());
|
|
22
|
-
}
|
|
39
|
+
resolveService(serviceClass);
|
|
23
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Resolves a service from the DI container.
|
|
43
|
+
* Creates a new instance if the service is not already registered.
|
|
44
|
+
* @param serviceClass - The service class to resolve
|
|
45
|
+
* @returns The singleton instance of the service
|
|
46
|
+
* @throws Error if the class is not decorated with @Injectable()
|
|
47
|
+
*/
|
|
24
48
|
function resolveService(serviceClass) {
|
|
25
49
|
if (!isInjectable(serviceClass)) {
|
|
26
50
|
throw new Error(`${serviceClass.name} is not injectable. Add @Injectable() decorator.`);
|
|
@@ -30,6 +54,11 @@ function resolveService(serviceClass) {
|
|
|
30
54
|
}
|
|
31
55
|
return container.get(serviceClass);
|
|
32
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Marks a constructor parameter for dependency injection.
|
|
59
|
+
* @param serviceClass - The service class to inject
|
|
60
|
+
* @returns A parameter decorator
|
|
61
|
+
*/
|
|
33
62
|
function Inject(serviceClass) {
|
|
34
63
|
return (target, propertyKey, parameterIndex) => {
|
|
35
64
|
const existingInjections = Reflect.getMetadata("injections", target) || new Map();
|
|
@@ -37,12 +66,26 @@ function Inject(serviceClass) {
|
|
|
37
66
|
Reflect.defineMetadata("injections", existingInjections, target);
|
|
38
67
|
};
|
|
39
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates an instance of a class with its dependencies automatically injected.
|
|
71
|
+
* @param targetClass - The class to instantiate
|
|
72
|
+
* @returns A new instance with all @Inject() dependencies resolved
|
|
73
|
+
*/
|
|
40
74
|
function createWithInjection(targetClass) {
|
|
41
75
|
const injections = Reflect.getMetadata("injections", targetClass) || new Map();
|
|
76
|
+
// Build constructor arguments from injections
|
|
42
77
|
const args = [];
|
|
43
78
|
injections.forEach((serviceClass, index) => {
|
|
44
79
|
args[index] = resolveService(serviceClass);
|
|
45
80
|
});
|
|
46
81
|
return new targetClass(...args);
|
|
47
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns all instances currently stored in the DI container.
|
|
85
|
+
* Useful for applying lifecycle operations to all services.
|
|
86
|
+
* @returns An array of all registered service instances
|
|
87
|
+
*/
|
|
88
|
+
function getContainerInstances() {
|
|
89
|
+
return Array.from(container.values());
|
|
90
|
+
}
|
|
48
91
|
//# sourceMappingURL=injectable.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectable.decorator.js","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"injectable.decorator.js","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":";;AAY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AI,GAAG,EAAE,CAAC;QAC3D,kBAAkB,CAAC,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;QACrD,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAC/B,WAAsC;IAEtC,MAAM,UAAU,GACZ,OAAO,CAAC,WAAW,CAAC,YAAY,EAAE,WAAW,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;IAEhE,8CAA8C;IAC9C,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,UAAU,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE;QACvC,IAAI,CAAC,KAAK,CAAC,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB;IACjC,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -1,11 +1,53 @@
|
|
|
1
1
|
import { FastifyInstance } from "fastify";
|
|
2
|
+
/**
|
|
3
|
+
* Marks a class as a controller with an optional route prefix.
|
|
4
|
+
* @param prefix - The base path prefix for all routes in this controller
|
|
5
|
+
* @returns A class decorator
|
|
6
|
+
*/
|
|
2
7
|
export declare function Controller(prefix?: string): ClassDecorator;
|
|
8
|
+
/**
|
|
9
|
+
* Marks a method as a GET route handler.
|
|
10
|
+
* @param path - The route path (optional)
|
|
11
|
+
* @returns A method decorator
|
|
12
|
+
*/
|
|
3
13
|
export declare const Get: (path?: string) => MethodDecorator;
|
|
14
|
+
/**
|
|
15
|
+
* Marks a method as a POST route handler.
|
|
16
|
+
* @param path - The route path (optional)
|
|
17
|
+
* @returns A method decorator
|
|
18
|
+
*/
|
|
4
19
|
export declare const Post: (path?: string) => MethodDecorator;
|
|
20
|
+
/**
|
|
21
|
+
* Marks a method as a PUT route handler.
|
|
22
|
+
* @param path - The route path (optional)
|
|
23
|
+
* @returns A method decorator
|
|
24
|
+
*/
|
|
5
25
|
export declare const Put: (path?: string) => MethodDecorator;
|
|
26
|
+
/**
|
|
27
|
+
* Marks a method as a DELETE route handler.
|
|
28
|
+
* @param path - The route path (optional)
|
|
29
|
+
* @returns A method decorator
|
|
30
|
+
*/
|
|
6
31
|
export declare const Delete: (path?: string) => MethodDecorator;
|
|
32
|
+
/**
|
|
33
|
+
* Marks a method as a PATCH route handler.
|
|
34
|
+
* @param path - The route path (optional)
|
|
35
|
+
* @returns A method decorator
|
|
36
|
+
*/
|
|
7
37
|
export declare const Patch: (path?: string) => MethodDecorator;
|
|
8
38
|
type ControllerClass = new (...args: any[]) => object;
|
|
39
|
+
/**
|
|
40
|
+
* Registers a controller with a Fastify instance.
|
|
41
|
+
* Creates the controller with dependency injection and sets up all routes.
|
|
42
|
+
* @param fastify - The Fastify instance
|
|
43
|
+
* @param controllerClass - The controller class to register
|
|
44
|
+
*/
|
|
9
45
|
export declare function registerController(fastify: FastifyInstance, controllerClass: ControllerClass): void;
|
|
46
|
+
/**
|
|
47
|
+
* Returns all registered controller instances.
|
|
48
|
+
* Useful for applying lifecycle operations to all controllers.
|
|
49
|
+
* @returns An array of all registered controller instances
|
|
50
|
+
*/
|
|
51
|
+
export declare function getControllerInstances(): object[];
|
|
10
52
|
export {};
|
|
11
53
|
//# sourceMappingURL=route.decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/route.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"route.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/route.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAuBxE;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,GAAE,MAAW,GAAG,cAAc,CAW9D;AAyBD;;;;GAIG;AACH,eAAO,MAAM,GAAG,UA1BE,MAAM,KAAQ,eA0Be,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,IAAI,UAjCC,MAAM,KAAQ,eAiCiB,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,GAAG,UAxCE,MAAM,KAAQ,eAwCe,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,MAAM,UA/CD,MAAM,KAAQ,eA+CqB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,KAAK,UAtDA,MAAM,KAAQ,eAsDmB,CAAC;AAGpD,KAAK,eAAe,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;AAKtD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,eAAe,EACxB,eAAe,EAAE,eAAe,GACjC,IAAI,CAgBN;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAEjD"}
|
|
@@ -3,14 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
|
|
4
4
|
exports.Controller = Controller;
|
|
5
5
|
exports.registerController = registerController;
|
|
6
|
+
exports.getControllerInstances = getControllerInstances;
|
|
6
7
|
const injectable_decorator_1 = require("./injectable.decorator");
|
|
8
|
+
// Metadata keys
|
|
7
9
|
const ROUTES_METADATA = Symbol("routes");
|
|
8
10
|
const CONTROLLER_PREFIX = Symbol("controller_prefix");
|
|
11
|
+
// Normalize path to ensure it starts with "/"
|
|
9
12
|
function normalizePath(path) {
|
|
10
13
|
if (!path)
|
|
11
14
|
return "";
|
|
12
15
|
return path.startsWith("/") ? path : `/${path}`;
|
|
13
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Marks a class as a controller with an optional route prefix.
|
|
19
|
+
* @param prefix - The base path prefix for all routes in this controller
|
|
20
|
+
* @returns A class decorator
|
|
21
|
+
*/
|
|
14
22
|
function Controller(prefix = "") {
|
|
15
23
|
return (target) => {
|
|
16
24
|
Reflect.defineMetadata(CONTROLLER_PREFIX, normalizePath(prefix), target);
|
|
@@ -19,6 +27,7 @@ function Controller(prefix = "") {
|
|
|
19
27
|
}
|
|
20
28
|
};
|
|
21
29
|
}
|
|
30
|
+
// Factory for HTTP method decorators
|
|
22
31
|
function createMethodDecorator(method) {
|
|
23
32
|
return (path = "") => {
|
|
24
33
|
return (target, propertyKey) => {
|
|
@@ -35,13 +44,47 @@ function createMethodDecorator(method) {
|
|
|
35
44
|
};
|
|
36
45
|
};
|
|
37
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Marks a method as a GET route handler.
|
|
49
|
+
* @param path - The route path (optional)
|
|
50
|
+
* @returns A method decorator
|
|
51
|
+
*/
|
|
38
52
|
exports.Get = createMethodDecorator("get");
|
|
53
|
+
/**
|
|
54
|
+
* Marks a method as a POST route handler.
|
|
55
|
+
* @param path - The route path (optional)
|
|
56
|
+
* @returns A method decorator
|
|
57
|
+
*/
|
|
39
58
|
exports.Post = createMethodDecorator("post");
|
|
59
|
+
/**
|
|
60
|
+
* Marks a method as a PUT route handler.
|
|
61
|
+
* @param path - The route path (optional)
|
|
62
|
+
* @returns A method decorator
|
|
63
|
+
*/
|
|
40
64
|
exports.Put = createMethodDecorator("put");
|
|
65
|
+
/**
|
|
66
|
+
* Marks a method as a DELETE route handler.
|
|
67
|
+
* @param path - The route path (optional)
|
|
68
|
+
* @returns A method decorator
|
|
69
|
+
*/
|
|
41
70
|
exports.Delete = createMethodDecorator("delete");
|
|
71
|
+
/**
|
|
72
|
+
* Marks a method as a PATCH route handler.
|
|
73
|
+
* @param path - The route path (optional)
|
|
74
|
+
* @returns A method decorator
|
|
75
|
+
*/
|
|
42
76
|
exports.Patch = createMethodDecorator("patch");
|
|
77
|
+
// Store registered controller instances
|
|
78
|
+
const controllerInstances = [];
|
|
79
|
+
/**
|
|
80
|
+
* Registers a controller with a Fastify instance.
|
|
81
|
+
* Creates the controller with dependency injection and sets up all routes.
|
|
82
|
+
* @param fastify - The Fastify instance
|
|
83
|
+
* @param controllerClass - The controller class to register
|
|
84
|
+
*/
|
|
43
85
|
function registerController(fastify, controllerClass) {
|
|
44
86
|
const controller = (0, injectable_decorator_1.createWithInjection)(controllerClass);
|
|
87
|
+
controllerInstances.push(controller);
|
|
45
88
|
const prefix = Reflect.getMetadata(CONTROLLER_PREFIX, controllerClass) || "";
|
|
46
89
|
const routes = Reflect.getMetadata(ROUTES_METADATA, controllerClass) || [];
|
|
47
90
|
for (const route of routes) {
|
|
@@ -50,4 +93,12 @@ function registerController(fastify, controllerClass) {
|
|
|
50
93
|
fastify[route.method](fullPath, handler);
|
|
51
94
|
}
|
|
52
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns all registered controller instances.
|
|
98
|
+
* Useful for applying lifecycle operations to all controllers.
|
|
99
|
+
* @returns An array of all registered controller instances
|
|
100
|
+
*/
|
|
101
|
+
function getControllerInstances() {
|
|
102
|
+
return controllerInstances;
|
|
103
|
+
}
|
|
53
104
|
//# sourceMappingURL=route.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.decorator.js","sourceRoot":"","sources":["../../../src/decorators/route.decorator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"route.decorator.js","sourceRoot":"","sources":["../../../src/decorators/route.decorator.ts"],"names":[],"mappings":";;;AA4BA,gCAWC;AAwED,gDAmBC;AAOD,wDAEC;AA1ID,iEAA6D;AAE7D,gBAAgB;AAChB,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACzC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;A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decorator.
|
|
3
|
+
*/
|
|
4
|
+
export type TimeoutOptions = {
|
|
5
|
+
/** Delay in milliseconds between each execution. */
|
|
6
|
+
ms: number;
|
|
7
|
+
/**
|
|
8
|
+
* Number of times to execute the method.
|
|
9
|
+
* Use -1 for infinite executions.
|
|
10
|
+
* @default 1
|
|
11
|
+
*/
|
|
12
|
+
times?: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Schedules a method to run repeatedly with a delay.
|
|
16
|
+
* The method will be executed after the initial delay, then repeat based on the times option.
|
|
17
|
+
* @param options - Configuration options for the timeout
|
|
18
|
+
* @returns A method decorator
|
|
19
|
+
*/
|
|
20
|
+
export declare function Timeout(options: TimeoutOptions): MethodDecorator;
|
|
21
|
+
/**
|
|
22
|
+
* Starts all @Timeout decorated methods on an instance.
|
|
23
|
+
* Call this after instantiating a class to begin scheduled executions.
|
|
24
|
+
* @param instance - The object instance containing @Timeout decorated methods
|
|
25
|
+
*/
|
|
26
|
+
export declare function startTimeouts(instance: object): void;
|
|
27
|
+
//# sourceMappingURL=timeout.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/timeout.decorator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IACzB,oDAAoD;IACpD,EAAE,EAAE,MAAM,CAAC;IACX;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AASF;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,eAAe,CAQhE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAwBpD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Timeout = Timeout;
|
|
4
|
+
exports.startTimeouts = startTimeouts;
|
|
5
|
+
const TIMEOUT_METADATA = Symbol("timeout");
|
|
6
|
+
/**
|
|
7
|
+
* Schedules a method to run repeatedly with a delay.
|
|
8
|
+
* The method will be executed after the initial delay, then repeat based on the times option.
|
|
9
|
+
* @param options - Configuration options for the timeout
|
|
10
|
+
* @returns A method decorator
|
|
11
|
+
*/
|
|
12
|
+
function Timeout(options) {
|
|
13
|
+
return (target, propertyKey, descriptor) => {
|
|
14
|
+
const existingTimeouts = Reflect.getMetadata(TIMEOUT_METADATA, target.constructor) || [];
|
|
15
|
+
existingTimeouts.push({ propertyKey, options });
|
|
16
|
+
Reflect.defineMetadata(TIMEOUT_METADATA, existingTimeouts, target.constructor);
|
|
17
|
+
return descriptor;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Starts all @Timeout decorated methods on an instance.
|
|
22
|
+
* Call this after instantiating a class to begin scheduled executions.
|
|
23
|
+
* @param instance - The object instance containing @Timeout decorated methods
|
|
24
|
+
*/
|
|
25
|
+
function startTimeouts(instance) {
|
|
26
|
+
const timeouts = Reflect.getMetadata(TIMEOUT_METADATA, instance.constructor) || [];
|
|
27
|
+
for (const { propertyKey, options } of timeouts) {
|
|
28
|
+
const method = instance[propertyKey];
|
|
29
|
+
if (typeof method === "function") {
|
|
30
|
+
const times = options.times ?? 1;
|
|
31
|
+
let executionCount = 0;
|
|
32
|
+
const execute = () => {
|
|
33
|
+
if (times === -1 || executionCount < times) {
|
|
34
|
+
executionCount++;
|
|
35
|
+
method.call(instance);
|
|
36
|
+
if (times === -1 || executionCount < times) {
|
|
37
|
+
setTimeout(execute, options.ms);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
setTimeout(execute, options.ms);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=timeout.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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KAAK,CAAC,CAAC,IAAI,cAAc,GAAG,KAAK,EAAE,CAAC;wBACzC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;oBACpC,CAAC;gBACL,CAAC;YACL,CAAC,CAAC;YAEF,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QACpC,CAAC;IACL,CAAC;AACL,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
export { createWithInjection, Inject, Injectable, isInjectable, registerService, resolveService } from "./decorators/injectable.decorator.js";
|
|
3
|
-
export {
|
|
2
|
+
export { createWithInjection, getContainerInstances, Inject, Injectable, isInjectable, registerService, resolveService } from "./decorators/injectable.decorator.js";
|
|
3
|
+
export { startTimeouts, Timeout, TimeoutOptions } from "./decorators/timeout.decorator.js";
|
|
4
|
+
export { Controller, Delete, Get, getControllerInstances, Patch, Post, Put, registerController } from "./decorators/route.decorator.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAG1B,OAAO,EACH,mBAAmB,EACnB,MAAM,EACN,UAAU,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACjB,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAG1B,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EACrB,MAAM,EACN,UAAU,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACjB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACH,aAAa,EACb,OAAO,EACP,cAAc,EACjB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EACH,UAAU,EACV,MAAM,EACN,GAAG,EACH,sBAAsB,EACtB,KAAK,EACL,IAAI,EACJ,GAAG,EACH,kBAAkB,EACrB,MAAM,iCAAiC,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerController = exports.Put = exports.Post = exports.Patch = exports.Get = exports.Delete = exports.Controller = exports.resolveService = exports.registerService = exports.isInjectable = exports.Injectable = exports.Inject = exports.createWithInjection = void 0;
|
|
3
|
+
exports.registerController = exports.Put = exports.Post = exports.Patch = exports.getControllerInstances = exports.Get = exports.Delete = exports.Controller = exports.Timeout = exports.startTimeouts = exports.resolveService = exports.registerService = exports.isInjectable = exports.Injectable = exports.Inject = exports.getContainerInstances = exports.createWithInjection = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
|
+
// Dependency Injection
|
|
5
6
|
var injectable_decorator_js_1 = require("./decorators/injectable.decorator.js");
|
|
6
7
|
Object.defineProperty(exports, "createWithInjection", { enumerable: true, get: function () { return injectable_decorator_js_1.createWithInjection; } });
|
|
8
|
+
Object.defineProperty(exports, "getContainerInstances", { enumerable: true, get: function () { return injectable_decorator_js_1.getContainerInstances; } });
|
|
7
9
|
Object.defineProperty(exports, "Inject", { enumerable: true, get: function () { return injectable_decorator_js_1.Inject; } });
|
|
8
10
|
Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return injectable_decorator_js_1.Injectable; } });
|
|
9
11
|
Object.defineProperty(exports, "isInjectable", { enumerable: true, get: function () { return injectable_decorator_js_1.isInjectable; } });
|
|
10
12
|
Object.defineProperty(exports, "registerService", { enumerable: true, get: function () { return injectable_decorator_js_1.registerService; } });
|
|
11
13
|
Object.defineProperty(exports, "resolveService", { enumerable: true, get: function () { return injectable_decorator_js_1.resolveService; } });
|
|
14
|
+
var timeout_decorator_js_1 = require("./decorators/timeout.decorator.js");
|
|
15
|
+
Object.defineProperty(exports, "startTimeouts", { enumerable: true, get: function () { return timeout_decorator_js_1.startTimeouts; } });
|
|
16
|
+
Object.defineProperty(exports, "Timeout", { enumerable: true, get: function () { return timeout_decorator_js_1.Timeout; } });
|
|
17
|
+
// Routing
|
|
12
18
|
var route_decorator_js_1 = require("./decorators/route.decorator.js");
|
|
13
19
|
Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return route_decorator_js_1.Controller; } });
|
|
14
20
|
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return route_decorator_js_1.Delete; } });
|
|
15
21
|
Object.defineProperty(exports, "Get", { enumerable: true, get: function () { return route_decorator_js_1.Get; } });
|
|
22
|
+
Object.defineProperty(exports, "getControllerInstances", { enumerable: true, get: function () { return route_decorator_js_1.getControllerInstances; } });
|
|
16
23
|
Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return route_decorator_js_1.Patch; } });
|
|
17
24
|
Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return route_decorator_js_1.Post; } });
|
|
18
25
|
Object.defineProperty(exports, "Put", { enumerable: true, get: function () { return route_decorator_js_1.Put; } });
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAE1B,uBAAuB;AACvB,gFAQ8C;AAP1C,8HAAA,mBAAmB,OAAA;AACnB,gIAAA,qBAAqB,OAAA;AACrB,iHAAA,MAAM,OAAA;AACN,qHAAA,UAAU,OAAA;AACV,uHAAA,YAAY,OAAA;AACZ,0HAAA,eAAe,OAAA;AACf,yHAAA,cAAc,OAAA;AAGlB,0EAI2C;AAHvC,qHAAA,aAAa,OAAA;AACb,+GAAA,OAAO,OAAA;AAIX,UAAU;AACV,sEASyC;AARrC,gHAAA,UAAU,OAAA;AACV,4GAAA,MAAM,OAAA;AACN,yGAAA,GAAG,OAAA;AACH,4HAAA,sBAAsB,OAAA;AACtB,2GAAA,KAAK,OAAA;AACL,0GAAA,IAAI,OAAA;AACJ,yGAAA,GAAG,OAAA;AACH,wHAAA,kBAAkB,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@albertoielpo/ielpify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A simplified way to build Fastify applications using decorators, inspired by NestJS",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"repository": {
|
|
46
46
|
"type": "git",
|
|
47
|
-
"url": "git+https://github.com/
|
|
47
|
+
"url": "git+https://github.com/albertoielpo/ielpify.git"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"fastify": ">=5.0.0",
|