@abejarano/ts-express-server 1.7.7 → 2.0.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/README.md CHANGED
@@ -1,22 +1,24 @@
1
1
  # TypeScript Server Framework (Bun)
2
2
 
3
- Un framework TypeScript moderno y modular para construir APIs en Bun con una arquitectura limpia, extensible y enfocada en productividad. Separa responsabilidades en modulos, servicios y controladores con decoradores, incluye middlewares esenciales listos para usar y mantiene una experiencia tipada end-to-end.
3
+ A modular and extensible TypeScript framework for building Bun servers with a clean architecture pattern that separates concerns between server modules and services.
4
4
 
5
5
  ## Features
6
6
 
7
- - 🏗️ **Arquitectura modular**: arma el servidor con modulos reutilizables y reemplazables
8
- - 🚀 **Servicios de fondo**: inicia procesos y workers junto al servidor
9
- - 📦 **Modulos incluidos**: CORS, seguridad, rate limit, uploads y contexto de request
10
- - 🔄 **Apagado limpio**: shutdown ordenado y seguro para modulos/servicios
11
- - ⚡ **Prioridades**: control total del orden de inicializacion
12
- - 🛡️ **Type safety real**: tipado fuerte en request, response y decoradores
13
- - 🔧 **Configurable**: cambia o desactiva piezas sin romper el core
14
- - 🎨 **Decoradores**: controladores claros, declarativos y faciles de testear
7
+ - 🏗️ **Modular Architecture**: Build your server using reusable modules
8
+ - 🚀 **Service Management**: Integrate background services that start with your server
9
+ - 📦 **Built-in Modules**: Pre-configured modules for common functionality
10
+ - 🔄 **Graceful Shutdown**: Proper cleanup and shutdown handling
11
+ - ⚡ **Priority System**: Control module initialization order
12
+ - 🛡️ **Type Safety**: Full TypeScript support with strong typing
13
+ - 🔧 **Configurable**: Highly customizable modules and services
14
+ - 🎨 **Decorators**: Clean and declarative controller definition
15
15
 
16
16
  ## Installation
17
17
 
18
18
  ```bash
19
- bun add @abejarano/ts-express-server
19
+ npm install @abejarano/ts-express-server
20
+ # or
21
+ yarn add @abejarano/ts-express-server
20
22
  ```
21
23
 
22
24
  ## Documentation
@@ -1,5 +1,5 @@
1
1
  import { BootstrapServer } from "./BootstrapServer";
2
- import { ControllersModule } from "./modules";
2
+ import { ControllersModule, RoutesModule } from "./modules";
3
3
  import { BaseServerModule, BaseServerService, ServerAdapter } from "./abstract";
4
4
  export interface BootstrapStandardServerOptions {
5
5
  adapter?: ServerAdapter;
@@ -13,6 +13,9 @@ export interface BootstrapStandardServerOptions {
13
13
  };
14
14
  services?: BaseServerService[];
15
15
  }
16
- export declare function BootstrapStandardServer(port: number, module: ControllersModule, services?: BaseServerService[]): BootstrapServer;
17
- export declare function BootstrapStandardServer(port: number, module: ControllersModule, services: BaseServerService[], options: BootstrapStandardServerOptions): BootstrapServer;
18
- export declare function BootstrapStandardServer(port: number, module: ControllersModule, options: BootstrapStandardServerOptions): BootstrapServer;
16
+ export declare function BootstrapStandardServer(port: number, module: RoutesModule | ControllersModule, services?: BaseServerService[]): BootstrapServer;
17
+ export declare function BootstrapStandardServer(port: number, module: RoutesModule | ControllersModule, services: BaseServerService[], options: BootstrapStandardServerOptions): BootstrapServer;
18
+ export declare function BootstrapStandardServer(port: number, module: RoutesModule | ControllersModule, options: BootstrapStandardServerOptions): BootstrapServer;
19
+ export declare function BootstrapStandardServer(port: number, routes: RoutesModule, controllersModule: ControllersModule, services?: BaseServerService[]): BootstrapServer;
20
+ export declare function BootstrapStandardServer(port: number, routes: RoutesModule, controllersModule: ControllersModule, services: BaseServerService[], options: BootstrapStandardServerOptions): BootstrapServer;
21
+ export declare function BootstrapStandardServer(port: number, routes: RoutesModule, controllersModule: ControllersModule, options: BootstrapStandardServerOptions): BootstrapServer;
@@ -3,11 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BootstrapStandardServer = BootstrapStandardServer;
4
4
  const BootstrapServer_1 = require("./BootstrapServer");
5
5
  const modules_1 = require("./modules");
6
- function BootstrapStandardServer(port, arg2, arg3, arg4) {
6
+ function BootstrapStandardServer(port, arg2, arg3, arg4, arg5) {
7
+ let routesModule;
7
8
  let controllersModule;
8
9
  let services;
9
10
  let options;
10
- controllersModule = arg2;
11
+ const setControllersModule = (module) => {
12
+ if (controllersModule && controllersModule !== module) {
13
+ throw new Error("ControllersModule provided multiple times. Pass a single instance only.");
14
+ }
15
+ controllersModule = module;
16
+ };
17
+ if (arg2 instanceof modules_1.RoutesModule) {
18
+ routesModule = arg2;
19
+ }
20
+ else if (arg2 instanceof modules_1.ControllersModule) {
21
+ setControllersModule(arg2);
22
+ routesModule = new modules_1.RoutesModule();
23
+ }
24
+ else {
25
+ throw new Error("Invalid second argument. Must be RoutesModule or ControllersModule");
26
+ }
11
27
  const addServices = (value) => {
12
28
  if (!value?.length) {
13
29
  return;
@@ -18,6 +34,10 @@ function BootstrapStandardServer(port, arg2, arg3, arg4) {
18
34
  if (!value) {
19
35
  return;
20
36
  }
37
+ if (value instanceof modules_1.ControllersModule) {
38
+ setControllersModule(value);
39
+ return;
40
+ }
21
41
  if (Array.isArray(value)) {
22
42
  addServices(value);
23
43
  return;
@@ -26,8 +46,9 @@ function BootstrapStandardServer(port, arg2, arg3, arg4) {
26
46
  };
27
47
  processOptionalArg(arg3);
28
48
  processOptionalArg(arg4);
49
+ processOptionalArg(arg5);
29
50
  addServices(options?.services);
30
- const modulesToRegister = [controllersModule];
51
+ const modulesToRegister = [routesModule];
31
52
  const preset = options?.modules;
32
53
  const registerModule = (factory, override) => {
33
54
  if (override === false) {
@@ -46,6 +67,9 @@ function BootstrapStandardServer(port, arg2, arg3, arg4) {
46
67
  const server = new BootstrapServer_1.BootstrapServer(port, {
47
68
  adapter: options?.adapter,
48
69
  }).addModules(modulesToRegister);
70
+ if (controllersModule) {
71
+ server.addModule(controllersModule);
72
+ }
49
73
  if (services) {
50
74
  server.addServices(services);
51
75
  }
@@ -138,8 +138,7 @@ class BunResponse {
138
138
  ? filename
139
139
  : path_1.default.basename(safePath);
140
140
  this.headers.set("content-disposition", `attachment; filename="${sanitizeFilename(resolvedName)}"`);
141
- const fileBuffer = (0, fs_1.readFileSync)(safePath);
142
- this.rawResponse = new Response(fileBuffer);
141
+ this.rawResponse = new Response(Bun.file(safePath));
143
142
  this.ended = true;
144
143
  this.resolveEnd?.();
145
144
  callback?.();
@@ -0,0 +1,2 @@
1
+ import { ServerRouter } from "./abstract";
2
+ export declare const createRouter: () => ServerRouter;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRouter = void 0;
4
+ const adapters_1 = require("./adapters");
5
+ const createRouter = () => {
6
+ return new adapters_1.BunAdapter().createRouter();
7
+ };
8
+ exports.createRouter = createRouter;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export type { BootstrapServerOptions } from "./BootstrapServer";
4
4
  export { BootstrapStandardServer } from "./BootstrapStandardServer";
5
5
  export type { BootstrapStandardServerOptions } from "./BootstrapStandardServer";
6
6
  export * from "./adapters";
7
+ export * from "./createRouter";
7
8
  export * from "./modules";
8
9
  export * from "./abstract";
9
10
  export * from "./decorators";
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "BootstrapServer", { enumerable: true, get: funct
21
21
  var BootstrapStandardServer_1 = require("./BootstrapStandardServer");
22
22
  Object.defineProperty(exports, "BootstrapStandardServer", { enumerable: true, get: function () { return BootstrapStandardServer_1.BootstrapStandardServer; } });
23
23
  __exportStar(require("./adapters"), exports);
24
+ __exportStar(require("./createRouter"), exports);
24
25
  __exportStar(require("./modules"), exports);
25
26
  __exportStar(require("./abstract"), exports);
26
27
  __exportStar(require("./decorators"), exports);
@@ -0,0 +1,17 @@
1
+ import { BaseServerModule } from "../abstract";
2
+ import { ServerApp, ServerContext, ServerHandler, ServerRouter } from "../abstract";
3
+ export interface RouteConfig {
4
+ path: string;
5
+ router: ServerRouter;
6
+ middleware?: ServerHandler[] | ServerHandler;
7
+ }
8
+ export declare class RoutesModule extends BaseServerModule {
9
+ name: string;
10
+ priority: number;
11
+ private routes;
12
+ constructor(routes?: RouteConfig[]);
13
+ getModuleName(): string;
14
+ addRoute(route: RouteConfig): void;
15
+ addRoutes(routes: RouteConfig[]): void;
16
+ init(app: ServerApp, context?: ServerContext): void;
17
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RoutesModule = void 0;
4
+ const abstract_1 = require("../abstract");
5
+ class RoutesModule extends abstract_1.BaseServerModule {
6
+ constructor(routes = []) {
7
+ super();
8
+ this.name = "Routes";
9
+ this.priority = 10; // Executed after basic middlewares
10
+ this.routes = routes;
11
+ }
12
+ getModuleName() {
13
+ return this.name;
14
+ }
15
+ addRoute(route) {
16
+ this.routes.push({
17
+ ...route,
18
+ });
19
+ }
20
+ addRoutes(routes) {
21
+ this.routes.push(...routes);
22
+ }
23
+ init(app, context) {
24
+ this.routes.forEach(({ path, router, middleware }) => {
25
+ const middlewareList = Array.isArray(middleware)
26
+ ? middleware
27
+ : middleware
28
+ ? [middleware]
29
+ : [];
30
+ if (middlewareList.length > 0) {
31
+ app.use(path, ...middlewareList, router);
32
+ }
33
+ else {
34
+ app.use(path, router);
35
+ }
36
+ });
37
+ }
38
+ }
39
+ exports.RoutesModule = RoutesModule;
@@ -3,4 +3,5 @@ export * from "./ControllersModule";
3
3
  export * from "./FileUploadModule";
4
4
  export * from "./RateLimitModule";
5
5
  export * from "./RequestContextModule";
6
+ export * from "./RoutesModule";
6
7
  export * from "./SecurityModule";
@@ -19,4 +19,5 @@ __exportStar(require("./ControllersModule"), exports);
19
19
  __exportStar(require("./FileUploadModule"), exports);
20
20
  __exportStar(require("./RateLimitModule"), exports);
21
21
  __exportStar(require("./RequestContextModule"), exports);
22
+ __exportStar(require("./RoutesModule"), exports);
22
23
  __exportStar(require("./SecurityModule"), exports);
package/package.json CHANGED
@@ -1,24 +1,27 @@
1
1
  {
2
2
  "name": "@abejarano/ts-express-server",
3
3
  "author": "angel bejarano / angel.bejarano@jaspesoft.com",
4
- "version": "1.7.7",
4
+ "version": "2.0.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "build": "bun run tsc -p tsconfig.json",
12
- "clean": "rm -rf dist",
13
- "prepare": "bun run build",
14
- "prebuild": "bun run clean",
15
- "format": "bun run prettier --write .",
16
- "format:check": "bun run prettier --check .",
17
- "typecheck": "bun run tsc --noEmit",
18
- "prepack": "bun run build",
19
- "test": "bun test",
20
- "test:watch": "bun test --watch",
21
- "test:coverage": "bun test --coverage"
11
+ "build": "tsc -p tsconfig.json",
12
+ "clean": "rimraf dist",
13
+ "prepare": "yarn build",
14
+ "prebuild": "yarn clean",
15
+ "format": "prettier --write .",
16
+ "format:check": "prettier --check .",
17
+ "typecheck": "tsc --noEmit",
18
+ "prepack": "yarn build",
19
+ "version:patch": "npm version patch",
20
+ "version:minor": "npm version minor",
21
+ "version:major": "npm version major",
22
+ "test": "jest",
23
+ "test:watch": "jest --watch",
24
+ "test:coverage": "jest --coverage"
22
25
  },
23
26
  "keywords": [
24
27
  "server",
@@ -36,13 +39,17 @@
36
39
  "@semantic-release/changelog": "^6.0.3",
37
40
  "@semantic-release/git": "^10.0.1",
38
41
  "@types/cors": "^2.8.19",
39
- "bun-types": "^1.3.5",
42
+ "@types/jest": "^30.0.0",
43
+ "@types/node": "^25.0.3",
44
+ "jest": "^30.2.0",
40
45
  "prettier": "^3.6.2",
46
+ "rimraf": "^6.0.1",
41
47
  "semantic-release": "^25.0.2",
48
+ "ts-jest": "^29.4.5",
42
49
  "typescript": "^5.9.3"
43
50
  },
44
51
  "engines": {
45
- "bun": ">=1.3.5"
52
+ "node": ">=20"
46
53
  },
47
54
  "repository": {
48
55
  "type": "git",