@engjts/nexus 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/BENCHMARK_REPORT.md +343 -0
  2. package/dist/advanced/playground/generatePlaygroundHTML.d.ts.map +1 -1
  3. package/dist/advanced/playground/generatePlaygroundHTML.js +107 -0
  4. package/dist/advanced/playground/generatePlaygroundHTML.js.map +1 -1
  5. package/dist/advanced/playground/playground.d.ts +19 -0
  6. package/dist/advanced/playground/playground.d.ts.map +1 -1
  7. package/dist/advanced/playground/playground.js +70 -0
  8. package/dist/advanced/playground/playground.js.map +1 -1
  9. package/dist/advanced/playground/types.d.ts +20 -0
  10. package/dist/advanced/playground/types.d.ts.map +1 -1
  11. package/dist/cli/templates/generators.d.ts.map +1 -1
  12. package/dist/cli/templates/generators.js +16 -13
  13. package/dist/cli/templates/generators.js.map +1 -1
  14. package/dist/cli/templates/index.js +25 -25
  15. package/dist/core/application.d.ts +14 -0
  16. package/dist/core/application.d.ts.map +1 -1
  17. package/dist/core/application.js +173 -71
  18. package/dist/core/application.js.map +1 -1
  19. package/dist/core/context-pool.d.ts +2 -13
  20. package/dist/core/context-pool.d.ts.map +1 -1
  21. package/dist/core/context-pool.js +7 -45
  22. package/dist/core/context-pool.js.map +1 -1
  23. package/dist/core/context.d.ts +108 -5
  24. package/dist/core/context.d.ts.map +1 -1
  25. package/dist/core/context.js +449 -53
  26. package/dist/core/context.js.map +1 -1
  27. package/dist/core/index.d.ts +1 -0
  28. package/dist/core/index.d.ts.map +1 -1
  29. package/dist/core/index.js +9 -1
  30. package/dist/core/index.js.map +1 -1
  31. package/dist/core/middleware.d.ts +6 -0
  32. package/dist/core/middleware.d.ts.map +1 -1
  33. package/dist/core/middleware.js +83 -84
  34. package/dist/core/middleware.js.map +1 -1
  35. package/dist/core/performance/fast-json.d.ts +149 -0
  36. package/dist/core/performance/fast-json.d.ts.map +1 -0
  37. package/dist/core/performance/fast-json.js +473 -0
  38. package/dist/core/performance/fast-json.js.map +1 -0
  39. package/dist/core/router/file-router.d.ts +20 -7
  40. package/dist/core/router/file-router.d.ts.map +1 -1
  41. package/dist/core/router/file-router.js +41 -13
  42. package/dist/core/router/file-router.js.map +1 -1
  43. package/dist/core/router/index.d.ts +6 -0
  44. package/dist/core/router/index.d.ts.map +1 -1
  45. package/dist/core/router/index.js +33 -6
  46. package/dist/core/router/index.js.map +1 -1
  47. package/dist/core/router/radix-tree.d.ts +4 -1
  48. package/dist/core/router/radix-tree.d.ts.map +1 -1
  49. package/dist/core/router/radix-tree.js +7 -3
  50. package/dist/core/router/radix-tree.js.map +1 -1
  51. package/dist/core/serializer.d.ts +251 -0
  52. package/dist/core/serializer.d.ts.map +1 -0
  53. package/dist/core/serializer.js +290 -0
  54. package/dist/core/serializer.js.map +1 -0
  55. package/dist/core/types.d.ts +39 -1
  56. package/dist/core/types.d.ts.map +1 -1
  57. package/dist/core/types.js.map +1 -1
  58. package/dist/index.d.ts +1 -0
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +12 -2
  61. package/dist/index.js.map +1 -1
  62. package/package.json +3 -1
  63. package/src/advanced/playground/generatePlaygroundHTML.ts +107 -0
  64. package/src/advanced/playground/playground.ts +225 -145
  65. package/src/advanced/playground/types.ts +29 -0
  66. package/src/cli/templates/generators.ts +16 -13
  67. package/src/cli/templates/index.ts +25 -25
  68. package/src/core/application.ts +202 -84
  69. package/src/core/context-pool.ts +8 -56
  70. package/src/core/context.ts +497 -53
  71. package/src/core/index.ts +14 -0
  72. package/src/core/middleware.ts +99 -89
  73. package/src/core/router/file-router.ts +41 -12
  74. package/src/core/router/index.ts +213 -180
  75. package/src/core/router/radix-tree.ts +20 -4
  76. package/src/core/serializer.ts +397 -0
  77. package/src/core/types.ts +43 -1
  78. package/src/index.ts +17 -0
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/advanced/playground/types.ts"],"names":[],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AE1B,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEnC,sDAAsD;IACtD,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,sEAAsE;IACtE,IAAI,CAAC,EAAE;QACH,wCAAwC;QACxC,QAAQ,EAAE,MAAM,CAAC;QACjB,wCAAwC;QACxC,QAAQ,EAAE,MAAM,CAAC;KACpB,CAAC;CACL;AAGD,MAAM,WAAW,WAAW;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,CAAC,EAAE,SAAS,CAAC;CACpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../../../src/cli/templates/generators.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG,OAAO,GAAG,aAAa,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;AAE/G,UAAU,eAAe;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,gBAAgB;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,qBAAa,kBAAkB;IAC7B,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,eAAe;IAqBvF,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,kBAAkB;IA6C1B,OAAO,CAAC,kBAAkB;IAyB1B,OAAO,CAAC,kBAAkB;IA4D1B,OAAO,CAAC,eAAe;IAwEvB,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,iBAAiB;CA8C1B"}
1
+ {"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../../../src/cli/templates/generators.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG,OAAO,GAAG,aAAa,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;AAE/G,UAAU,eAAe;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,gBAAgB;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,qBAAa,kBAAkB;IAC7B,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,eAAe;IAqBvF,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,kBAAkB;IA6C1B,OAAO,CAAC,kBAAkB;IAyB1B,OAAO,CAAC,kBAAkB;IA+D1B,OAAO,CAAC,eAAe;IAwEvB,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,iBAAiB;CA8C1B"}
@@ -127,47 +127,50 @@ export const ${middlewareName}Middleware: Middleware = async (ctx: Context, next
127
127
  @Controller('/${baseName}')
128
128
  export class ${className} {
129
129
  @Get('/')
130
- async getAll(ctx: Context) {
131
- return ctx.json({
130
+ async getAll() {
131
+ return {
132
132
  message: 'Get all ${baseName}',
133
133
  data: [],
134
- });
134
+ };
135
135
  }
136
136
 
137
137
  @Get('/:id')
138
138
  async getById(ctx: Context) {
139
139
  const { id } = ctx.params;
140
- return ctx.json({
140
+ return {
141
141
  message: \`Get ${baseName} by id: \${id}\`,
142
142
  data: null,
143
- });
143
+ };
144
144
  }
145
145
 
146
146
  @Post('/')
147
147
  async create(ctx: Context) {
148
148
  const body = await ctx.body();
149
- return ctx.json({
150
- message: 'Create ${baseName}',
151
- data: body,
152
- }, 201);
149
+ return {
150
+ status: 201,
151
+ data: {
152
+ message: 'Create ${baseName}',
153
+ data: body,
154
+ },
155
+ };
153
156
  }
154
157
 
155
158
  @Put('/:id')
156
159
  async update(ctx: Context) {
157
160
  const { id } = ctx.params;
158
161
  const body = await ctx.body();
159
- return ctx.json({
162
+ return {
160
163
  message: \`Update ${baseName}: \${id}\`,
161
164
  data: body,
162
- });
165
+ };
163
166
  }
164
167
 
165
168
  @Delete('/:id')
166
169
  async delete(ctx: Context) {
167
170
  const { id } = ctx.params;
168
- return ctx.json({
171
+ return {
169
172
  message: \`Delete ${baseName}: \${id}\`,
170
- });
173
+ };
171
174
  }
172
175
  }
173
176
  `;
@@ -1 +1 @@
1
- {"version":3,"file":"generators.js","sourceRoot":"","sources":["../../../src/cli/templates/generators.ts"],"names":[],"mappings":";;;AAYA,MAAa,kBAAkB;IAC7B,QAAQ,CAAC,IAAmB,EAAE,IAAY,EAAE,OAAyB;QACnE,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YACnD,KAAK,aAAa;gBAChB,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YACxD,KAAK,YAAY;gBACf,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACvC,KAAK,YAAY;gBACf,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACvC,KAAK,SAAS;gBACZ,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YACpC,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAClC,KAAK,WAAW;gBACd,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACtC;gBACE,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;QACvD,CA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AAC,aAAa,EAAE,EAAE,CAAC,CAAC;QACjD,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAE/C,MAAM,OAAO,GAAG;;;qBAGC,UAAU;;;;;;;;qBAQV,UAAU;;;;;;;eAOhB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;;;;;;;;;eAS1B,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;;;;;oBAKrB,UAAU,gCAAgC,UAAU;oBACpD,UAAU,gCAAgC,UAAU;cAC1D,UAAU,0BAA0B,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;CAC3E,CAAC;QAEE,OAAO;YACL,QAAQ,EAAE,kBAAkB,IAAI,KAAK;YACrC,OAAO;SACR,CAAC;IACJ,CAAC;CACF;AA1VD,gDA0VC"}
@@ -252,18 +252,18 @@ app.listen(PORT, () => {
252
252
 
253
253
  export const routes = new Router();
254
254
 
255
- routes.get('/', async (ctx) => {
256
- return ctx.json({
255
+ routes.get('/', async () => {
256
+ return {
257
257
  message: 'Welcome to Nexus!',
258
258
  version: '1.0.0',
259
- });
259
+ };
260
260
  });
261
261
 
262
- routes.get('/health', async (ctx) => {
263
- return ctx.json({
262
+ routes.get('/health', async () => {
263
+ return {
264
264
  status: 'ok',
265
265
  timestamp: new Date().toISOString(),
266
- });
266
+ };
267
267
  });
268
268
  `;
269
269
  }
@@ -299,21 +299,21 @@ import { userRoutes } from './users';
299
299
  export const routes = new Router();
300
300
 
301
301
  // Health check
302
- routes.get('/health', async (ctx) => {
303
- return ctx.json({
302
+ routes.get('/health', async () => {
303
+ return {
304
304
  status: 'ok',
305
305
  timestamp: new Date().toISOString(),
306
306
  uptime: process.uptime(),
307
- });
307
+ };
308
308
  });
309
309
 
310
310
  // API info
311
- routes.get('/api', async (ctx) => {
312
- return ctx.json({
311
+ routes.get('/api', async () => {
312
+ return {
313
313
  name: 'API',
314
314
  version: '1.0.0',
315
315
  endpoints: ['/api/users', '/health'],
316
- });
316
+ };
317
317
  });
318
318
 
319
319
  // Mount user routes
@@ -321,7 +321,7 @@ routes.group('/api/users', userRoutes);
321
321
  `;
322
322
  }
323
323
  getUserRoutes() {
324
- return `import { Router } from '@engjts/nexus';
324
+ return `import { Router, HttpError } from '@engjts/nexus';
325
325
  import { UserService } from '../services/user.service';
326
326
  import { createUserSchema, updateUserSchema } from '../validators/user.validator';
327
327
 
@@ -329,9 +329,9 @@ export const userRoutes = new Router();
329
329
  const userService = new UserService();
330
330
 
331
331
  // GET /api/users
332
- userRoutes.get('/', async (ctx) => {
332
+ userRoutes.get('/', async () => {
333
333
  const users = await userService.findAll();
334
- return ctx.json({ users });
334
+ return { users };
335
335
  });
336
336
 
337
337
  // GET /api/users/:id
@@ -340,10 +340,10 @@ userRoutes.get('/:id', async (ctx) => {
340
340
  const user = await userService.findById(id);
341
341
 
342
342
  if (!user) {
343
- return ctx.json({ error: 'User not found' }, 404);
343
+ throw new HttpError(404, 'User not found');
344
344
  }
345
345
 
346
- return ctx.json({ user });
346
+ return { user };
347
347
  });
348
348
 
349
349
  // POST /api/users
@@ -352,7 +352,7 @@ userRoutes.post('/', async (ctx) => {
352
352
  const validated = createUserSchema.parse(body);
353
353
 
354
354
  const user = await userService.create(validated);
355
- return ctx.json({ user }, 201);
355
+ return { status: 201, data: { user } };
356
356
  });
357
357
 
358
358
  // PUT /api/users/:id
@@ -364,10 +364,10 @@ userRoutes.put('/:id', async (ctx) => {
364
364
  const user = await userService.update(id, validated);
365
365
 
366
366
  if (!user) {
367
- return ctx.json({ error: 'User not found' }, 404);
367
+ throw new HttpError(404, 'User not found');
368
368
  }
369
369
 
370
- return ctx.json({ user });
370
+ return { user };
371
371
  });
372
372
 
373
373
  // DELETE /api/users/:id
@@ -376,21 +376,21 @@ userRoutes.delete('/:id', async (ctx) => {
376
376
  const deleted = await userService.delete(id);
377
377
 
378
378
  if (!deleted) {
379
- return ctx.json({ error: 'User not found' }, 404);
379
+ throw new HttpError(404, 'User not found');
380
380
  }
381
381
 
382
- return ctx.json({ message: 'User deleted successfully' });
382
+ return { message: 'User deleted successfully' };
383
383
  });
384
384
  `;
385
385
  }
386
386
  getAuthMiddleware() {
387
- return `import { Middleware, Context } from '@engjts/nexus';
387
+ return `import { Middleware, Context, HttpError } from '@engjts/nexus';
388
388
 
389
389
  export const authMiddleware: Middleware = async (ctx: Context, next) => {
390
390
  const authHeader = ctx.headers.get('authorization');
391
391
 
392
392
  if (!authHeader || !authHeader.startsWith('Bearer ')) {
393
- return ctx.json({ error: 'Unauthorized' }, 401);
393
+ throw new HttpError(401, 'Unauthorized');
394
394
  }
395
395
 
396
396
  const token = authHeader.slice(7);
@@ -402,7 +402,7 @@ export const authMiddleware: Middleware = async (ctx: Context, next) => {
402
402
 
403
403
  return next();
404
404
  } catch (error) {
405
- return ctx.json({ error: 'Invalid token' }, 401);
405
+ throw new HttpError(401, 'Invalid token');
406
406
  }
407
407
  };
408
408
  `;
@@ -490,14 +490,28 @@ export declare class Application<TDeps extends DependencyContainer = {}> {
490
490
  } | number | string): HTTPServer;
491
491
  /**
492
492
  * Handle incoming HTTP request
493
+ * Optimized hot path for maximum performance
493
494
  */
494
495
  private handleRequest;
496
+ /**
497
+ * Execute handler directly without middleware (fast path)
498
+ */
499
+ private executeHandlerDirect;
500
+ /**
501
+ * Cleanup request resources
502
+ */
503
+ private cleanupRequest;
504
+ /**
505
+ * Handle errors
506
+ */
507
+ private handleError;
495
508
  /**
496
509
  * Check if value is a Response object
497
510
  */
498
511
  private isResponse;
499
512
  /**
500
513
  * Send HTTP response
514
+ * Optimized for minimal overhead - key for benchmark performance
501
515
  */
502
516
  private sendResponse;
503
517
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../src/core/application.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAgB,MAAM,IAAI,UAAU,EAAmC,MAAM,MAAM,CAAC;AAC3F,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,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,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ/E;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/B;;OAEG;IACH,cAAc,IAAI,OAAO;IAIzB;;OAEG;IACH,kBAAkB,IAAI,uBAAuB,GAAG,SAAS;IAIzD;;;;OAIG;IACH,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,cAAc;IAQrD;;OAEG;IACH,iBAAiB,IAAI,cAAc,GAAG,SAAS;CAGlD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,WAAW,CAEzD"}
@@ -885,124 +885,181 @@ class Application {
885
885
  }
886
886
  /**
887
887
  * Handle incoming HTTP request
888
+ * Optimized hot path for maximum performance
888
889
  */
889
890
  async handleRequest(req, res) {
890
- let ctx = null;
891
- let response = null;
891
+ // Use non-null assertion - context pool always returns valid context
892
+ // acquire is now sync for better performance
893
+ const ctx = this.contextPool.acquire(req, res);
892
894
  try {
893
- // Acquire context from pool
894
- ctx = await this.contextPool.acquire(req, res);
895
- // Inject store registry into context
896
- if ('setStoreRegistry' in ctx && typeof ctx.setStoreRegistry === 'function') {
897
- ctx.setStoreRegistry(this.storeRegistry);
898
- }
899
- // Set debug mode for request stores
900
- if ('setDebugMode' in ctx && typeof ctx.setDebugMode === 'function') {
901
- ctx.setDebugMode(this.config.debug ?? false);
902
- }
903
- // === HOOK: onRequest ===
895
+ // Direct method calls - ContextImpl always has these methods
896
+ ctx.setStoreRegistry(this.storeRegistry);
897
+ ctx.setDebugMode(this.config.debug ?? false);
898
+ // === HOOK: onRequest (skip check if no hooks) ===
904
899
  if (this.lifecycleHooks.onRequest) {
905
900
  const hookResult = await this.lifecycleHooks.onRequest(ctx);
906
- if (this.isResponse(hookResult)) {
901
+ if (hookResult && typeof hookResult === 'object' && 'statusCode' in hookResult) {
907
902
  await this.sendResponse(res, hookResult, ctx);
903
+ this.cleanupRequest(ctx);
908
904
  return;
909
905
  }
910
906
  }
911
- // Apply versioning if configured
907
+ // Fast path: no versioning configured (most common)
912
908
  let matchPath = ctx.path;
913
909
  if (this.versioningConfig) {
914
910
  const { version, basePath, source } = this.resolveVersion(ctx);
915
911
  ctx.version = version;
916
912
  ctx.versionSource = source;
917
- // For header/query strategy, rewrite path to versioned path
918
- if (source === 'header' || source === 'query' || source === 'default') {
913
+ if (source !== 'path') {
919
914
  matchPath = `/${version}${basePath.startsWith('/') ? basePath : '/' + basePath}`;
920
915
  }
921
- if (this.config.debug) {
922
- console.log(`[Versioning] ${source} → ${version}, path: ${ctx.path} → ${matchPath}`);
923
- }
924
916
  }
925
917
  // Find matching route
926
918
  const match = this.router.match(ctx.method, matchPath);
927
919
  if (!match) {
928
- // Try fallback handler (e.g., static files)
920
+ // Try fallback handler
929
921
  if (this.fallbackHandler) {
930
922
  const fallbackResponse = await this.fallbackHandler(ctx, this.dependencies);
931
923
  await this.sendResponse(res, fallbackResponse, ctx);
924
+ this.cleanupRequest(ctx);
932
925
  return;
933
926
  }
934
- // 404 Not Found
935
- await this.sendResponse(res, {
936
- statusCode: 404,
937
- headers: { 'Content-Type': 'application/json' },
938
- body: JSON.stringify({ error: 'Not Found' })
939
- }, ctx);
927
+ // 404 Not Found - use cached response
928
+ res.writeHead(404, { 'Content-Type': 'application/json' });
929
+ res.end('{"error":"Not Found"}');
930
+ this.cleanupRequest(ctx);
940
931
  return;
941
932
  }
942
- // Set route params
943
- if ('setParams' in ctx && typeof ctx.setParams === 'function') {
944
- ctx.setParams(match.params);
933
+ // Set route params directly
934
+ ctx.params = match.params;
935
+ // Set serializers for fast JSON response if available
936
+ if (match._serializer) {
937
+ ctx.setSerializers(match._serializer);
938
+ }
939
+ // Auto-parse body for POST/PUT/PATCH if body exists
940
+ // This maintains backwards compatibility while keeping lazy-loading for GET
941
+ const method = ctx.method;
942
+ if (method === 'POST' || method === 'PUT' || method === 'PATCH') {
943
+ // Only parse if there's actually a body (Content-Length > 0 or Transfer-Encoding)
944
+ const contentLength = req.headers['content-length'];
945
+ const transferEncoding = req.headers['transfer-encoding'];
946
+ const hasBody = (contentLength && contentLength !== '0') || transferEncoding;
947
+ if (hasBody) {
948
+ await ctx.getBody();
949
+ }
950
+ }
951
+ // Fast path: no middleware
952
+ let response;
953
+ if (this.globalMiddlewares.length === 0 && match.middlewares.length === 0) {
954
+ // Direct handler execution (skip middleware executor)
955
+ response = await this.executeHandlerDirect(ctx, match.handler);
945
956
  }
946
957
  else {
947
- ctx.params = match.params;
958
+ // Combine global and route-specific middleware
959
+ const allMiddlewares = this.globalMiddlewares.length === 0
960
+ ? match.middlewares
961
+ : match.middlewares.length === 0
962
+ ? this.globalMiddlewares
963
+ : [...this.globalMiddlewares, ...match.middlewares];
964
+ // Execute middleware chain and handler with hooks
965
+ response = await this.middlewareExecutor.executeWithHooks(ctx, allMiddlewares, match.handler, this.lifecycleHooks, this.dependencies);
948
966
  }
949
- // Combine global and route-specific middleware
950
- const allMiddlewares = [...this.globalMiddlewares, ...match.middlewares];
951
- // Execute middleware chain and handler with hooks
952
- response = await this.middlewareExecutor.executeWithHooks(ctx, allMiddlewares, match.handler, this.lifecycleHooks, this.dependencies);
953
967
  // === HOOK: onResponse ===
954
968
  if (this.lifecycleHooks.onResponse) {
955
969
  const hookResult = await this.lifecycleHooks.onResponse(ctx, response);
956
- if (this.isResponse(hookResult)) {
970
+ if (hookResult && typeof hookResult === 'object' && 'statusCode' in hookResult) {
957
971
  response = hookResult;
958
972
  }
959
973
  }
960
974
  // Send response
961
975
  await this.sendResponse(res, response, ctx);
976
+ this.cleanupRequest(ctx);
962
977
  }
963
978
  catch (error) {
979
+ await this.handleError(error, ctx, res);
980
+ }
981
+ }
982
+ /**
983
+ * Execute handler directly without middleware (fast path)
984
+ */
985
+ async executeHandlerDirect(ctx, handler) {
986
+ // === HOOK: beforeHandler ===
987
+ if (this.lifecycleHooks.beforeHandler) {
988
+ const hookResult = await this.lifecycleHooks.beforeHandler(ctx);
989
+ if (hookResult && typeof hookResult === 'object' && 'statusCode' in hookResult) {
990
+ return hookResult;
991
+ }
992
+ }
993
+ let result = await handler(ctx, this.dependencies);
994
+ // If handler returns an Error, throw it
995
+ if (result instanceof Error) {
996
+ result._isIntentional = true;
997
+ throw result;
998
+ }
999
+ // === HOOK: afterHandler ===
1000
+ if (this.lifecycleHooks.afterHandler) {
1001
+ const transformedResult = await this.lifecycleHooks.afterHandler(ctx, result);
1002
+ if (transformedResult !== undefined) {
1003
+ result = transformedResult;
1004
+ }
1005
+ }
1006
+ // If result is a Response, return it
1007
+ if (result && typeof result === 'object' && 'statusCode' in result && 'body' in result) {
1008
+ return result;
1009
+ }
1010
+ // Otherwise, wrap in JSON response
1011
+ return ctx.json(result);
1012
+ }
1013
+ /**
1014
+ * Cleanup request resources
1015
+ */
1016
+ cleanupRequest(ctx) {
1017
+ // Dispose request-scoped stores
1018
+ if (ctx.disposeRequestStores) {
1019
+ ctx.disposeRequestStores();
1020
+ }
1021
+ // Release context back to pool
1022
+ this.contextPool.release(ctx);
1023
+ }
1024
+ /**
1025
+ * Handle errors
1026
+ */
1027
+ async handleError(error, ctx, res) {
1028
+ try {
964
1029
  // === HOOK: onError ===
965
1030
  if (ctx && this.lifecycleHooks.onError) {
966
1031
  try {
967
1032
  const hookResult = await this.lifecycleHooks.onError(ctx, error);
968
- if (this.isResponse(hookResult)) {
1033
+ if (hookResult && typeof hookResult === 'object' && 'statusCode' in hookResult) {
969
1034
  await this.sendResponse(res, hookResult, ctx);
1035
+ this.cleanupRequest(ctx);
970
1036
  return;
971
1037
  }
972
1038
  }
973
1039
  catch (hookError) {
974
- // Hook itself threw an error, continue to default error handler
975
1040
  console.error('onError hook failed:', hookError);
976
1041
  }
977
1042
  }
978
1043
  // Handle errors with default error handler
979
- try {
980
- const errorResponse = await this.errorHandler(error, ctx);
981
- // === HOOK: onResponse (for error responses) ===
982
- if (ctx && this.lifecycleHooks.onResponse) {
983
- const hookResult = await this.lifecycleHooks.onResponse(ctx, errorResponse);
984
- if (this.isResponse(hookResult)) {
985
- await this.sendResponse(res, hookResult, ctx);
986
- return;
987
- }
1044
+ const errorResponse = await this.errorHandler(error, ctx);
1045
+ // === HOOK: onResponse (for error responses) ===
1046
+ if (ctx && this.lifecycleHooks.onResponse) {
1047
+ const hookResult = await this.lifecycleHooks.onResponse(ctx, errorResponse);
1048
+ if (hookResult && typeof hookResult === 'object' && 'statusCode' in hookResult) {
1049
+ await this.sendResponse(res, hookResult, ctx);
1050
+ this.cleanupRequest(ctx);
1051
+ return;
988
1052
  }
989
- await this.sendResponse(res, errorResponse, ctx);
990
- }
991
- catch (handlerError) {
992
- // Fallback error response
993
- res.writeHead(500, { 'Content-Type': 'text/plain' });
994
- res.end('Internal Server Error');
995
1053
  }
1054
+ await this.sendResponse(res, errorResponse, ctx);
996
1055
  }
997
- finally {
998
- // Dispose request-scoped stores
999
- if (ctx && 'disposeRequestStores' in ctx && typeof ctx.disposeRequestStores === 'function') {
1000
- ctx.disposeRequestStores();
1001
- }
1002
- // Release context back to pool
1003
- if (ctx) {
1004
- this.contextPool.release(ctx);
1005
- }
1056
+ catch (handlerError) {
1057
+ // Fallback error response
1058
+ res.writeHead(500, { 'Content-Type': 'text/plain' });
1059
+ res.end('Internal Server Error');
1060
+ }
1061
+ if (ctx) {
1062
+ this.cleanupRequest(ctx);
1006
1063
  }
1007
1064
  }
1008
1065
  /**
@@ -1017,12 +1074,59 @@ class Application {
1017
1074
  }
1018
1075
  /**
1019
1076
  * Send HTTP response
1077
+ * Optimized for minimal overhead - key for benchmark performance
1020
1078
  */
1021
1079
  async sendResponse(res, response, ctx) {
1022
- // Set status code
1080
+ // Handle stream responses separately
1081
+ if (response.stream) {
1082
+ res.statusCode = response.statusCode;
1083
+ const headers = response.headers;
1084
+ for (const key in headers) {
1085
+ const value = headers[key];
1086
+ if (value !== undefined) {
1087
+ res.setHeader(key, value);
1088
+ }
1089
+ }
1090
+ response.stream.pipe(res);
1091
+ return;
1092
+ }
1093
+ const body = response.body;
1094
+ const headers = response.headers;
1095
+ // Fast path for JSON responses (most common case)
1096
+ // Use writeHead for single syscall instead of multiple setHeader calls
1097
+ if (headers['Content-Type'] === 'application/json') {
1098
+ // Calculate content length for proper HTTP behavior
1099
+ const contentLength = Buffer.byteLength(body, 'utf8');
1100
+ // Check if we need to set cookies
1101
+ let setCookies = null;
1102
+ if ('getSetCookieHeaders' in ctx && typeof ctx.getSetCookieHeaders === 'function') {
1103
+ const cookies = ctx.getSetCookieHeaders();
1104
+ if (cookies.length > 0) {
1105
+ setCookies = cookies;
1106
+ }
1107
+ }
1108
+ // Single writeHead call for all headers
1109
+ if (setCookies) {
1110
+ res.writeHead(response.statusCode, {
1111
+ 'Content-Type': 'application/json',
1112
+ 'Content-Length': contentLength,
1113
+ 'Set-Cookie': setCookies
1114
+ });
1115
+ }
1116
+ else {
1117
+ res.writeHead(response.statusCode, {
1118
+ 'Content-Type': 'application/json',
1119
+ 'Content-Length': contentLength
1120
+ });
1121
+ }
1122
+ res.end(body);
1123
+ return;
1124
+ }
1125
+ // General path for other response types
1023
1126
  res.statusCode = response.statusCode;
1024
- // Set headers
1025
- for (const [key, value] of Object.entries(response.headers)) {
1127
+ // Set headers using for-in (faster than Object.entries)
1128
+ for (const key in headers) {
1129
+ const value = headers[key];
1026
1130
  if (value !== undefined) {
1027
1131
  res.setHeader(key, value);
1028
1132
  }
@@ -1034,13 +1138,11 @@ class Application {
1034
1138
  res.setHeader('Set-Cookie', setCookies);
1035
1139
  }
1036
1140
  }
1037
- // Send body or stream
1038
- if (response.stream) {
1039
- response.stream.pipe(res);
1040
- }
1041
- else {
1042
- res.end(response.body);
1141
+ // Set Content-Length for non-stream responses
1142
+ if (body && typeof body === 'string') {
1143
+ res.setHeader('Content-Length', Buffer.byteLength(body, 'utf8'));
1043
1144
  }
1145
+ res.end(body);
1044
1146
  }
1045
1147
  /**
1046
1148
  * Get all registered routes