@albertoielpo/ielpify 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 ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 Alberto Ielpo <alberto.ielpo@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # @albertoielpo/ielpify
2
+
3
+ TypeScript decorators for Fastify: controllers, routing, and simple dependency injection.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @albertoielpo/ielpify
9
+ npm install reflect-metadata fastify # peer dependencies
10
+ ```
11
+
12
+ ## Decorators
13
+
14
+ ### Routing
15
+
16
+ - `@Controller(prefix?)` - Define a controller with optional route prefix
17
+ - `@Get(path?)`, `@Post(path?)`, `@Put(path?)`, `@Delete(path?)`, `@Patch(path?)` - HTTP method decorators
18
+
19
+ ### Dependency Injection
20
+
21
+ - `@Injectable()` - Mark a class as a singleton service
22
+ - `@Inject(ServiceClass)` - Inject a dependency
23
+
24
+ ### Functions
25
+
26
+ - `registerController(fastify, Controller)` - Register a controller with Fastify
27
+
28
+ ## Example
29
+
30
+ See the [example/](./example) folder for a complete working demo.
31
+
32
+ ```bash
33
+ cd example
34
+ npm install
35
+ npm run dev
36
+ ```
37
+
38
+ ## Development
39
+
40
+ To test changes locally without publishing:
41
+
42
+ ```bash
43
+ npm run build
44
+ mkdir -p example/node_modules/@albertoielpo/ielpify
45
+ cp -R dist example/node_modules/@albertoielpo/ielpify/
46
+ cp package.json example/node_modules/@albertoielpo/ielpify/
47
+ ```
48
+
49
+ ## License
50
+
51
+ MIT
@@ -0,0 +1,7 @@
1
+ export declare function Injectable(): ClassDecorator;
2
+ export declare function isInjectable(target: new () => object): boolean;
3
+ export declare function registerService<T extends object>(serviceClass: new () => T): void;
4
+ export declare function resolveService<T extends object>(serviceClass: new () => T): T;
5
+ export declare function Inject(serviceClass: new () => object): ParameterDecorator;
6
+ export declare function createWithInjection<T extends object>(targetClass: new (...args: any[]) => T): T;
7
+ //# sourceMappingURL=injectable.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectable.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":"AAOA,wBAAgB,UAAU,IAAI,cAAc,CAI3C;AAGD,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,MAAM,GAAG,OAAO,CAE9D;AAGD,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAC5C,YAAY,EAAE,UAAU,CAAC,GAC1B,IAAI,CAIN;AAGD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAU7E;AAGD,wBAAgB,MAAM,CAAC,YAAY,EAAE,UAAU,MAAM,GAAG,kBAAkB,CAOzE;AAGD,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EAEhD,WAAW,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GACvC,CAAC,CAWH"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Injectable = Injectable;
4
+ exports.isInjectable = isInjectable;
5
+ exports.registerService = registerService;
6
+ exports.resolveService = resolveService;
7
+ exports.Inject = Inject;
8
+ exports.createWithInjection = createWithInjection;
9
+ const container = new Map();
10
+ const INJECTABLE_METADATA = Symbol("injectable");
11
+ function Injectable() {
12
+ return (target) => {
13
+ Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
14
+ };
15
+ }
16
+ function isInjectable(target) {
17
+ return Reflect.getMetadata(INJECTABLE_METADATA, target) === true;
18
+ }
19
+ function registerService(serviceClass) {
20
+ if (!container.has(serviceClass)) {
21
+ container.set(serviceClass, new serviceClass());
22
+ }
23
+ }
24
+ function resolveService(serviceClass) {
25
+ if (!isInjectable(serviceClass)) {
26
+ throw new Error(`${serviceClass.name} is not injectable. Add @Injectable() decorator.`);
27
+ }
28
+ if (!container.has(serviceClass)) {
29
+ container.set(serviceClass, new serviceClass());
30
+ }
31
+ return container.get(serviceClass);
32
+ }
33
+ function Inject(serviceClass) {
34
+ return (target, propertyKey, parameterIndex) => {
35
+ const existingInjections = Reflect.getMetadata("injections", target) || new Map();
36
+ existingInjections.set(parameterIndex, serviceClass);
37
+ Reflect.defineMetadata("injections", existingInjections, target);
38
+ };
39
+ }
40
+ function createWithInjection(targetClass) {
41
+ const injections = Reflect.getMetadata("injections", targetClass) || new Map();
42
+ const args = [];
43
+ injections.forEach((serviceClass, index) => {
44
+ args[index] = resolveService(serviceClass);
45
+ });
46
+ return new targetClass(...args);
47
+ }
48
+ //# sourceMappingURL=injectable.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectable.decorator.js","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":";;AAOA,gCAIC;AAGD,oCAEC;AAGD,0CAMC;AAGD,wCAUC;AAGD,wBAOC;AAGD,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AAY,CAAC,CAAC;QACrD,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC,CAAC;AACN,CAAC;AAGD,SAAgB,mBAAmB,CAE/B,WAAsC;IAEtC,MAAM,UAAU,GACZ,OAAO,CAAC,WAAW,CAAC,YAAY,EAAE,WAAW,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;IAGhE,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"}
@@ -0,0 +1,11 @@
1
+ import { FastifyInstance } from "fastify";
2
+ export declare function Controller(prefix?: string): ClassDecorator;
3
+ export declare const Get: (path?: string) => MethodDecorator;
4
+ export declare const Post: (path?: string) => MethodDecorator;
5
+ export declare const Put: (path?: string) => MethodDecorator;
6
+ export declare const Delete: (path?: string) => MethodDecorator;
7
+ export declare const Patch: (path?: string) => MethodDecorator;
8
+ type ControllerClass = new (...args: any[]) => object;
9
+ export declare function registerController(fastify: FastifyInstance, controllerClass: ControllerClass): void;
10
+ export {};
11
+ //# sourceMappingURL=route.decorator.d.ts.map
@@ -0,0 +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;AAwBxE,wBAAgB,UAAU,CAAC,MAAM,GAAE,MAAW,GAAG,cAAc,CAW9D;AA0BD,eAAO,MAAM,GAAG,UAtBE,MAAM,KAAQ,eAsBe,CAAC;AAChD,eAAO,MAAM,IAAI,UAvBC,MAAM,KAAQ,eAuBiB,CAAC;AAClD,eAAO,MAAM,GAAG,UAxBE,MAAM,KAAQ,eAwBe,CAAC;AAChD,eAAO,MAAM,MAAM,UAzBD,MAAM,KAAQ,eAyBqB,CAAC;AACtD,eAAO,MAAM,KAAK,UA1BA,MAAM,KAAQ,eA0BmB,CAAC;AAIpD,KAAK,eAAe,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;AAGtD,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,eAAe,EACxB,eAAe,EAAE,eAAe,GACjC,IAAI,CAeN"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
4
+ exports.Controller = Controller;
5
+ exports.registerController = registerController;
6
+ const injectable_decorator_1 = require("./injectable.decorator");
7
+ const ROUTES_METADATA = Symbol("routes");
8
+ const CONTROLLER_PREFIX = Symbol("controller_prefix");
9
+ function normalizePath(path) {
10
+ if (!path)
11
+ return "";
12
+ return path.startsWith("/") ? path : `/${path}`;
13
+ }
14
+ function Controller(prefix = "") {
15
+ return (target) => {
16
+ Reflect.defineMetadata(CONTROLLER_PREFIX, normalizePath(prefix), target);
17
+ if (!Reflect.hasMetadata(ROUTES_METADATA, target)) {
18
+ Reflect.defineMetadata(ROUTES_METADATA, [], target);
19
+ }
20
+ };
21
+ }
22
+ function createMethodDecorator(method) {
23
+ return (path = "") => {
24
+ return (target, propertyKey) => {
25
+ const constructor = target.constructor;
26
+ const routes = Reflect.hasMetadata(ROUTES_METADATA, constructor)
27
+ ? Reflect.getMetadata(ROUTES_METADATA, constructor)
28
+ : [];
29
+ routes.push({
30
+ method,
31
+ path: normalizePath(path),
32
+ handlerName: String(propertyKey)
33
+ });
34
+ Reflect.defineMetadata(ROUTES_METADATA, routes, constructor);
35
+ };
36
+ };
37
+ }
38
+ exports.Get = createMethodDecorator("get");
39
+ exports.Post = createMethodDecorator("post");
40
+ exports.Put = createMethodDecorator("put");
41
+ exports.Delete = createMethodDecorator("delete");
42
+ exports.Patch = createMethodDecorator("patch");
43
+ function registerController(fastify, controllerClass) {
44
+ const controller = (0, injectable_decorator_1.createWithInjection)(controllerClass);
45
+ const prefix = Reflect.getMetadata(CONTROLLER_PREFIX, controllerClass) || "";
46
+ const routes = Reflect.getMetadata(ROUTES_METADATA, controllerClass) || [];
47
+ for (const route of routes) {
48
+ const fullPath = `${prefix}${route.path}` || "/";
49
+ const handler = controller[route.handlerName].bind(controller);
50
+ fastify[route.method](fullPath, handler);
51
+ }
52
+ }
53
+ //# sourceMappingURL=route.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.decorator.js","sourceRoot":"","sources":["../../../src/decorators/route.decorator.ts"],"names":[],"mappings":";;;AAwBA,gCAWC;AAqCD,gDAkBC;AAzFD,iEAA6D;AAG7D,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACzC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAMtD,SAAS,aAAa,CAAC,IAAY;IAC/B,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;AACpD,CAAC;AAUD,SAAgB,UAAU,CAAC,SAAiB,EAAE;IAC1C,OAAO,CAAC,MAAM,EAAE,EAAE;QACd,OAAO,CAAC,cAAc,CAClB,iBAAiB,EACjB,aAAa,CAAC,MAAM,CAAC,EACrB,MAAM,CACT,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,eAAe,EAAE,MAAM,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,cAAc,CAAC,eAAe,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QACxD,CAAC;IACL,CAAC,CAAC;AACN,CAAC;AAGD,SAAS,qBAAqB,CAAC,M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,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC;QACjD,MAAM,OAAO,GAAI,UAA2C,CACxD,KAAK,CAAC,WAAW,CACpB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEnB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import "reflect-metadata";
2
+ export { createWithInjection, Inject, Injectable, isInjectable, registerService, resolveService } from "./decorators/injectable.decorator.js";
3
+ export { Controller, Delete, Get, Patch, Post, Put, registerController } from "./decorators/route.decorator.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAG9C,OAAO,EACH,UAAU,EACV,MAAM,EACN,GAAG,EACH,KAAK,EACL,IAAI,EACJ,GAAG,EACH,kBAAkB,EACrB,MAAM,iCAAiC,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
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;
4
+ require("reflect-metadata");
5
+ var injectable_decorator_js_1 = require("./decorators/injectable.decorator.js");
6
+ Object.defineProperty(exports, "createWithInjection", { enumerable: true, get: function () { return injectable_decorator_js_1.createWithInjection; } });
7
+ Object.defineProperty(exports, "Inject", { enumerable: true, get: function () { return injectable_decorator_js_1.Inject; } });
8
+ Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return injectable_decorator_js_1.Injectable; } });
9
+ Object.defineProperty(exports, "isInjectable", { enumerable: true, get: function () { return injectable_decorator_js_1.isInjectable; } });
10
+ Object.defineProperty(exports, "registerService", { enumerable: true, get: function () { return injectable_decorator_js_1.registerService; } });
11
+ Object.defineProperty(exports, "resolveService", { enumerable: true, get: function () { return injectable_decorator_js_1.resolveService; } });
12
+ var route_decorator_js_1 = require("./decorators/route.decorator.js");
13
+ Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return route_decorator_js_1.Controller; } });
14
+ Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return route_decorator_js_1.Delete; } });
15
+ Object.defineProperty(exports, "Get", { enumerable: true, get: function () { return route_decorator_js_1.Get; } });
16
+ Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return route_decorator_js_1.Patch; } });
17
+ Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return route_decorator_js_1.Post; } });
18
+ Object.defineProperty(exports, "Put", { enumerable: true, get: function () { return route_decorator_js_1.Put; } });
19
+ Object.defineProperty(exports, "registerController", { enumerable: true, get: function () { return route_decorator_js_1.registerController; } });
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAG1B,gFAO8C;AAN1C,8HAAA,mBAAmB,OAAA;AACnB,iHAAA,MAAM,OAAA;AACN,qHAAA,UAAU,OAAA;AACV,uHAAA,YAAY,OAAA;AACZ,0HAAA,eAAe,OAAA;AACf,yHAAA,cAAc,OAAA;AAIlB,sEAQyC;AAPrC,gHAAA,UAAU,OAAA;AACV,4GAAA,MAAM,OAAA;AACN,yGAAA,GAAG,OAAA;AACH,2GAAA,KAAK,OAAA;AACL,0GAAA,IAAI,OAAA;AACJ,yGAAA,GAAG,OAAA;AACH,wHAAA,kBAAkB,OAAA"}
@@ -0,0 +1,7 @@
1
+ export declare function Injectable(): ClassDecorator;
2
+ export declare function isInjectable(target: new () => object): boolean;
3
+ export declare function registerService<T extends object>(serviceClass: new () => T): void;
4
+ export declare function resolveService<T extends object>(serviceClass: new () => T): T;
5
+ export declare function Inject(serviceClass: new () => object): ParameterDecorator;
6
+ export declare function createWithInjection<T extends object>(targetClass: new (...args: any[]) => T): T;
7
+ //# sourceMappingURL=injectable.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectable.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":"AAOA,wBAAgB,UAAU,IAAI,cAAc,CAI3C;AAGD,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,MAAM,GAAG,OAAO,CAE9D;AAGD,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAC5C,YAAY,EAAE,UAAU,CAAC,GAC1B,IAAI,CAIN;AAGD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAU7E;AAGD,wBAAgB,MAAM,CAAC,YAAY,EAAE,UAAU,MAAM,GAAG,kBAAkB,CAOzE;AAGD,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EAEhD,WAAW,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GACvC,CAAC,CAWH"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Injectable = Injectable;
4
+ exports.isInjectable = isInjectable;
5
+ exports.registerService = registerService;
6
+ exports.resolveService = resolveService;
7
+ exports.Inject = Inject;
8
+ exports.createWithInjection = createWithInjection;
9
+ const container = new Map();
10
+ const INJECTABLE_METADATA = Symbol("injectable");
11
+ function Injectable() {
12
+ return (target) => {
13
+ Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
14
+ };
15
+ }
16
+ function isInjectable(target) {
17
+ return Reflect.getMetadata(INJECTABLE_METADATA, target) === true;
18
+ }
19
+ function registerService(serviceClass) {
20
+ if (!container.has(serviceClass)) {
21
+ container.set(serviceClass, new serviceClass());
22
+ }
23
+ }
24
+ function resolveService(serviceClass) {
25
+ if (!isInjectable(serviceClass)) {
26
+ throw new Error(`${serviceClass.name} is not injectable. Add @Injectable() decorator.`);
27
+ }
28
+ if (!container.has(serviceClass)) {
29
+ container.set(serviceClass, new serviceClass());
30
+ }
31
+ return container.get(serviceClass);
32
+ }
33
+ function Inject(serviceClass) {
34
+ return (target, propertyKey, parameterIndex) => {
35
+ const existingInjections = Reflect.getMetadata("injections", target) || new Map();
36
+ existingInjections.set(parameterIndex, serviceClass);
37
+ Reflect.defineMetadata("injections", existingInjections, target);
38
+ };
39
+ }
40
+ function createWithInjection(targetClass) {
41
+ const injections = Reflect.getMetadata("injections", targetClass) || new Map();
42
+ const args = [];
43
+ injections.forEach((serviceClass, index) => {
44
+ args[index] = resolveService(serviceClass);
45
+ });
46
+ return new targetClass(...args);
47
+ }
48
+ //# sourceMappingURL=injectable.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectable.decorator.js","sourceRoot":"","sources":["../../../src/decorators/injectable.decorator.ts"],"names":[],"mappings":";;AAOA,gCAIC;AAGD,oCAEC;AAGD,0CAMC;AAGD,wCAUC;AAGD,wBAOC;AAGD,kDAcC;AAhED,MAAM,SAAS,GAAG,IAAI,GAAG,EAA4B,CAAC;AAGtD,MAAM,mBAAmB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAGjD,SAAgB,UAAU;IACtB,OAAO,CAAC,MAAM,EAAE,EAAE;QACd,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC,CAAC;AACN,CAAC;AAGD,SAAgB,YAAY,CAAC,MAAwB;IACjD,OAAO,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;AACrE,CAAC;AAGD,SAAgB,eAAe,CAC3B,YAAy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IAC/C,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { FastifyInstance } from "fastify";
2
+ export declare function Controller(prefix?: string): ClassDecorator;
3
+ export declare const Get: (path?: string) => MethodDecorator;
4
+ export declare const Post: (path?: string) => MethodDecorator;
5
+ export declare const Put: (path?: string) => MethodDecorator;
6
+ export declare const Delete: (path?: string) => MethodDecorator;
7
+ export declare const Patch: (path?: string) => MethodDecorator;
8
+ type ControllerClass = new (...args: any[]) => object;
9
+ export declare function registerController(fastify: FastifyInstance, controllerClass: ControllerClass): void;
10
+ export {};
11
+ //# sourceMappingURL=route.decorator.d.ts.map
@@ -0,0 +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;AAwBxE,wBAAgB,UAAU,CAAC,MAAM,GAAE,MAAW,GAAG,cAAc,CAW9D;AA0BD,eAAO,MAAM,GAAG,UAtBE,MAAM,KAAQ,eAsBe,CAAC;AAChD,eAAO,MAAM,IAAI,UAvBC,MAAM,KAAQ,eAuBiB,CAAC;AAClD,eAAO,MAAM,GAAG,UAxBE,MAAM,KAAQ,eAwBe,CAAC;AAChD,eAAO,MAAM,MAAM,UAzBD,MAAM,KAAQ,eAyBqB,CAAC;AACtD,eAAO,MAAM,KAAK,UA1BA,MAAM,KAAQ,eA0BmB,CAAC;AAIpD,KAAK,eAAe,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;AAGtD,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,eAAe,EACxB,eAAe,EAAE,eAAe,GACjC,IAAI,CAeN"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
4
+ exports.Controller = Controller;
5
+ exports.registerController = registerController;
6
+ const injectable_decorator_1 = require("./injectable.decorator");
7
+ const ROUTES_METADATA = Symbol("routes");
8
+ const CONTROLLER_PREFIX = Symbol("controller_prefix");
9
+ function normalizePath(path) {
10
+ if (!path)
11
+ return "";
12
+ return path.startsWith("/") ? path : `/${path}`;
13
+ }
14
+ function Controller(prefix = "") {
15
+ return (target) => {
16
+ Reflect.defineMetadata(CONTROLLER_PREFIX, normalizePath(prefix), target);
17
+ if (!Reflect.hasMetadata(ROUTES_METADATA, target)) {
18
+ Reflect.defineMetadata(ROUTES_METADATA, [], target);
19
+ }
20
+ };
21
+ }
22
+ function createMethodDecorator(method) {
23
+ return (path = "") => {
24
+ return (target, propertyKey) => {
25
+ const constructor = target.constructor;
26
+ const routes = Reflect.hasMetadata(ROUTES_METADATA, constructor)
27
+ ? Reflect.getMetadata(ROUTES_METADATA, constructor)
28
+ : [];
29
+ routes.push({
30
+ method,
31
+ path: normalizePath(path),
32
+ handlerName: String(propertyKey)
33
+ });
34
+ Reflect.defineMetadata(ROUTES_METADATA, routes, constructor);
35
+ };
36
+ };
37
+ }
38
+ exports.Get = createMethodDecorator("get");
39
+ exports.Post = createMethodDecorator("post");
40
+ exports.Put = createMethodDecorator("put");
41
+ exports.Delete = createMethodDecorator("delete");
42
+ exports.Patch = createMethodDecorator("patch");
43
+ function registerController(fastify, controllerClass) {
44
+ const controller = (0, injectable_decorator_1.createWithInjection)(controllerClass);
45
+ const prefix = Reflect.getMetadata(CONTROLLER_PREFIX, controllerClass) || "";
46
+ const routes = Reflect.getMetadata(ROUTES_METADATA, controllerClass) || [];
47
+ for (const route of routes) {
48
+ const fullPath = `${prefix}${route.path}` || "/";
49
+ const handler = controller[route.handlerName].bind(controller);
50
+ fastify[route.method](fullPath, handler);
51
+ }
52
+ }
53
+ //# sourceMappingURL=route.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.decorator.js","source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,WAAW,CAAC;aACnC,CAAC,CAAC;YAEH,OAAO,CAAC,cAAc,CAAC,eAAe,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACjE,CAAC,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AAGY,QAAA,GAAG,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;AACnC,QAAA,IAAI,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACrC,QAAA,GAAG,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;AACnC,QAAA,MAAM,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AACzC,QAAA,KAAK,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;AAOpD,SAAgB,kBAAkB,CAC9B,OAAwB,EACxB,eAAgC;IAEhC,MAAM,UAAU,GAAG,IAAA,0CAAmB,EAAC,eAAe,CAAC,CAAC;IACxD,MAAM,MAAM,GACR,OAAO,CAAC,WAAW,CAAC,iBAAiB,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC;IAClE,MAAM,MAAM,GACR,OAAO,CAAC,WAAW,CAAC,eAAe,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC;IAEhE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC;QACjD,MAAM,OAAO,GAAI,UAA2C,CACxD,KAAK,CAAC,WAAW,CACpB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEnB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import "reflect-metadata";
2
+ export { createWithInjection, Inject, Injectable, isInjectable, registerService, resolveService } from "./decorators/injectable.decorator.js";
3
+ export { Controller, Delete, Get, Patch, Post, Put, registerController } from "./decorators/route.decorator.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAG9C,OAAO,EACH,UAAU,EACV,MAAM,EACN,GAAG,EACH,KAAK,EACL,IAAI,EACJ,GAAG,EACH,kBAAkB,EACrB,MAAM,iCAAiC,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
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;
4
+ require("reflect-metadata");
5
+ var injectable_decorator_js_1 = require("./decorators/injectable.decorator.js");
6
+ Object.defineProperty(exports, "createWithInjection", { enumerable: true, get: function () { return injectable_decorator_js_1.createWithInjection; } });
7
+ Object.defineProperty(exports, "Inject", { enumerable: true, get: function () { return injectable_decorator_js_1.Inject; } });
8
+ Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return injectable_decorator_js_1.Injectable; } });
9
+ Object.defineProperty(exports, "isInjectable", { enumerable: true, get: function () { return injectable_decorator_js_1.isInjectable; } });
10
+ Object.defineProperty(exports, "registerService", { enumerable: true, get: function () { return injectable_decorator_js_1.registerService; } });
11
+ Object.defineProperty(exports, "resolveService", { enumerable: true, get: function () { return injectable_decorator_js_1.resolveService; } });
12
+ var route_decorator_js_1 = require("./decorators/route.decorator.js");
13
+ Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return route_decorator_js_1.Controller; } });
14
+ Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return route_decorator_js_1.Delete; } });
15
+ Object.defineProperty(exports, "Get", { enumerable: true, get: function () { return route_decorator_js_1.Get; } });
16
+ Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return route_decorator_js_1.Patch; } });
17
+ Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return route_decorator_js_1.Post; } });
18
+ Object.defineProperty(exports, "Put", { enumerable: true, get: function () { return route_decorator_js_1.Put; } });
19
+ Object.defineProperty(exports, "registerController", { enumerable: true, get: function () { return route_decorator_js_1.registerController; } });
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAG1B,gFAO8C;AAN1C,8HAAA,mBAAmB,OAAA;AACnB,iHAAA,MAAM,OAAA;AACN,qHAAA,UAAU,OAAA;AACV,uHAAA,YAAY,OAAA;AACZ,0HAAA,eAAe,OAAA;AACf,yHAAA,cAAc,OAAA;AAIlB,sEAQyC;AAPrC,gHAAA,UAAU,OAAA;AACV,4GAAA,MAAM,OAAA;AACN,yGAAA,GAAG,OAAA;AACH,2GAAA,KAAK,OAAA;AACL,0GAAA,IAAI,OAAA;AACJ,yGAAA,GAAG,OAAA;AACH,wHAAA,kBAAkB,OAAA"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@albertoielpo/ielpify",
3
+ "version": "0.1.0",
4
+ "description": "A simplified way to build Fastify applications using decorators, inspired by NestJS",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/cjs/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/esm/index.d.ts",
12
+ "default": "./dist/esm/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/cjs/index.d.ts",
16
+ "default": "./dist/cjs/index.js"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "npm run build:cjs && npm run build:esm",
25
+ "build:cjs": "tsc -p tsconfig.cjs.json",
26
+ "build:esm": "tsc -p tsconfig.esm.json",
27
+ "prepublish": "npm run build",
28
+ "format": "prettier --write \"src/**/*.ts\""
29
+ },
30
+ "keywords": [
31
+ "fastify",
32
+ "decorators",
33
+ "typescript",
34
+ "nestjs",
35
+ "dependency-injection",
36
+ "di",
37
+ "controllers",
38
+ "routing"
39
+ ],
40
+ "author": "Alberto Ielpo <alberto.ielpo@gmail.com>",
41
+ "license": "MIT",
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/ielpo/ielpify.git"
48
+ },
49
+ "peerDependencies": {
50
+ "fastify": ">=5.0.0",
51
+ "reflect-metadata": ">=0.1.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^24.0.0",
55
+ "fastify": "~5.7.1",
56
+ "prettier": "~3.6.2",
57
+ "reflect-metadata": "~0.2.2",
58
+ "typescript": "~5.9.2"
59
+ },
60
+ "engines": {
61
+ "node": ">=24",
62
+ "npm": ">=11"
63
+ }
64
+ }