express-fastify-runtime 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +326 -0
- package/changelog/README.md +5 -0
- package/changelog/log-2025-02-07.md +10 -0
- package/changelog/log-2026-06-25.md +151 -0
- package/dist/app/ExpressLikeApp.d.ts +9 -0
- package/dist/app/ExpressLikeApp.d.ts.map +1 -0
- package/dist/app/ExpressLikeApp.js +64 -0
- package/dist/app/ExpressLikeApp.js.map +1 -0
- package/dist/app/RouteStore.d.ts +17 -0
- package/dist/app/RouteStore.d.ts.map +1 -0
- package/dist/app/RouteStore.js +43 -0
- package/dist/app/RouteStore.js.map +1 -0
- package/dist/app/classify.d.ts +8 -0
- package/dist/app/classify.d.ts.map +1 -0
- package/dist/app/classify.js +25 -0
- package/dist/app/classify.js.map +1 -0
- package/dist/app/compile.d.ts +25 -0
- package/dist/app/compile.d.ts.map +1 -0
- package/dist/app/compile.js +195 -0
- package/dist/app/compile.js.map +1 -0
- package/dist/app/flattenRouter.d.ts +51 -0
- package/dist/app/flattenRouter.d.ts.map +1 -0
- package/dist/app/flattenRouter.js +126 -0
- package/dist/app/flattenRouter.js.map +1 -0
- package/dist/app/introspectExpress.d.ts +29 -0
- package/dist/app/introspectExpress.d.ts.map +1 -0
- package/dist/app/introspectExpress.js +60 -0
- package/dist/app/introspectExpress.js.map +1 -0
- package/dist/examples/auth.d.ts +6 -0
- package/dist/examples/auth.d.ts.map +1 -0
- package/dist/examples/auth.js +26 -0
- package/dist/examples/auth.js.map +1 -0
- package/dist/examples/logging.d.ts +6 -0
- package/dist/examples/logging.d.ts.map +1 -0
- package/dist/examples/logging.js +25 -0
- package/dist/examples/logging.js.map +1 -0
- package/dist/examples/uploads.d.ts +6 -0
- package/dist/examples/uploads.d.ts.map +1 -0
- package/dist/examples/uploads.js +21 -0
- package/dist/examples/uploads.js.map +1 -0
- package/dist/express/engine.d.ts +6 -0
- package/dist/express/engine.d.ts.map +1 -0
- package/dist/express/engine.js +14 -0
- package/dist/express/engine.js.map +1 -0
- package/dist/express/middleware.d.ts +15 -0
- package/dist/express/middleware.d.ts.map +1 -0
- package/dist/express/middleware.js +32 -0
- package/dist/express/middleware.js.map +1 -0
- package/dist/express/mount.d.ts +35 -0
- package/dist/express/mount.d.ts.map +1 -0
- package/dist/express/mount.js +78 -0
- package/dist/express/mount.js.map +1 -0
- package/dist/fastify/adapters/middleware.d.ts +8 -0
- package/dist/fastify/adapters/middleware.d.ts.map +1 -0
- package/dist/fastify/adapters/middleware.js +29 -0
- package/dist/fastify/adapters/middleware.js.map +1 -0
- package/dist/fastify/adapters/request.d.ts +19 -0
- package/dist/fastify/adapters/request.d.ts.map +1 -0
- package/dist/fastify/adapters/request.js +258 -0
- package/dist/fastify/adapters/request.js.map +1 -0
- package/dist/fastify/adapters/response.d.ts +19 -0
- package/dist/fastify/adapters/response.d.ts.map +1 -0
- package/dist/fastify/adapters/response.js +667 -0
- package/dist/fastify/adapters/response.js.map +1 -0
- package/dist/fastify/register.d.ts +12 -0
- package/dist/fastify/register.d.ts.map +1 -0
- package/dist/fastify/register.js +15 -0
- package/dist/fastify/register.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/decorators.d.ts +7 -0
- package/dist/runtime/decorators.d.ts.map +1 -0
- package/dist/runtime/decorators.js +17 -0
- package/dist/runtime/decorators.js.map +1 -0
- package/dist/runtime/errorHandler.d.ts +13 -0
- package/dist/runtime/errorHandler.d.ts.map +1 -0
- package/dist/runtime/errorHandler.js +95 -0
- package/dist/runtime/errorHandler.js.map +1 -0
- package/dist/runtime/expressLane.d.ts +40 -0
- package/dist/runtime/expressLane.d.ts.map +1 -0
- package/dist/runtime/expressLane.js +71 -0
- package/dist/runtime/expressLane.js.map +1 -0
- package/dist/runtime/fast.d.ts +43 -0
- package/dist/runtime/fast.d.ts.map +1 -0
- package/dist/runtime/fast.js +150 -0
- package/dist/runtime/fast.js.map +1 -0
- package/dist/runtime/lifecycle.d.ts +10 -0
- package/dist/runtime/lifecycle.d.ts.map +1 -0
- package/dist/runtime/lifecycle.js +152 -0
- package/dist/runtime/lifecycle.js.map +1 -0
- package/dist/runtime/populateExpress.d.ts +7 -0
- package/dist/runtime/populateExpress.d.ts.map +1 -0
- package/dist/runtime/populateExpress.js +27 -0
- package/dist/runtime/populateExpress.js.map +1 -0
- package/dist/types/express.d.ts +97 -0
- package/dist/types/express.d.ts.map +1 -0
- package/dist/types/express.js +12 -0
- package/dist/types/express.js.map +1 -0
- package/dist/types/internal.d.ts +60 -0
- package/dist/types/internal.d.ts.map +1 -0
- package/dist/types/internal.js +7 -0
- package/dist/types/internal.js.map +1 -0
- package/dist/utils/assert.d.ts +6 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +17 -0
- package/dist/utils/assert.js.map +1 -0
- package/dist/utils/detect.d.ts +14 -0
- package/dist/utils/detect.d.ts.map +1 -0
- package/dist/utils/detect.js +64 -0
- package/dist/utils/detect.js.map +1 -0
- package/dist/utils/maxListeners.d.ts +28 -0
- package/dist/utils/maxListeners.d.ts.map +1 -0
- package/dist/utils/maxListeners.js +50 -0
- package/dist/utils/maxListeners.js.map +1 -0
- package/dist/utils/patchRouterLayer.d.ts +12 -0
- package/dist/utils/patchRouterLayer.d.ts.map +1 -0
- package/dist/utils/patchRouterLayer.js +96 -0
- package/dist/utils/patchRouterLayer.js.map +1 -0
- package/dist/utils/path.d.ts +6 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +23 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/runtimeLogger.d.ts +15 -0
- package/dist/utils/runtimeLogger.d.ts.map +1 -0
- package/dist/utils/runtimeLogger.js +28 -0
- package/dist/utils/runtimeLogger.js.map +1 -0
- package/dist/utils/unwrap.d.ts +12 -0
- package/dist/utils/unwrap.d.ts.map +1 -0
- package/dist/utils/unwrap.js +24 -0
- package/dist/utils/unwrap.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Boot, lock, listen. Compile once; no dynamic routing.
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createApp = createApp;
|
|
10
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
11
|
+
const classify_1 = require("../app/classify");
|
|
12
|
+
const engine_1 = require("../express/engine");
|
|
13
|
+
const mount_1 = require("../express/mount");
|
|
14
|
+
const register_1 = require("../fastify/register");
|
|
15
|
+
const populateExpress_1 = require("./populateExpress");
|
|
16
|
+
const assert_1 = require("../utils/assert");
|
|
17
|
+
const errorHandler_1 = require("./errorHandler");
|
|
18
|
+
const request_1 = require("../fastify/adapters/request");
|
|
19
|
+
const response_1 = require("../fastify/adapters/response");
|
|
20
|
+
const RouteStore_1 = require("../app/RouteStore");
|
|
21
|
+
const flattenRouter_1 = require("../app/flattenRouter");
|
|
22
|
+
const path_1 = require("../utils/path");
|
|
23
|
+
const runtimeLogger_1 = require("../utils/runtimeLogger");
|
|
24
|
+
function createApp(options) {
|
|
25
|
+
const routeStore = new RouteStore_1.RouteStore();
|
|
26
|
+
const locked = { current: false };
|
|
27
|
+
const runtimeLogger = (0, runtimeLogger_1.createRuntimeLogger)(options);
|
|
28
|
+
const app = {
|
|
29
|
+
use(pathOrHandler, ...handlers) {
|
|
30
|
+
(0, assert_1.assertNotLocked)(locked.current);
|
|
31
|
+
const path = typeof pathOrHandler === 'string' ? (0, path_1.normalizePath)(pathOrHandler) : '/';
|
|
32
|
+
const allHandlers = typeof pathOrHandler === 'string' ? handlers : [pathOrHandler, ...handlers];
|
|
33
|
+
let middlewareGroup = [];
|
|
34
|
+
for (const h of allHandlers) {
|
|
35
|
+
if ((0, flattenRouter_1.isExpressRouter)(h)) {
|
|
36
|
+
if (middlewareGroup.length > 0) {
|
|
37
|
+
routeStore.addMiddleware(path, ...middlewareGroup);
|
|
38
|
+
middlewareGroup = [];
|
|
39
|
+
}
|
|
40
|
+
const flat = (0, flattenRouter_1.flattenRouter)(h, path);
|
|
41
|
+
if (flat !== null) {
|
|
42
|
+
routeStore.addEntries(flat);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
runtimeLogger.warnDowngrade('express.Router (middleware or RegExp path). Tip: import express-fastify-runtime before Express or routers so middleware paths can be detected');
|
|
46
|
+
routeStore.addMiddleware(path, h);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
middlewareGroup.push(h);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (middlewareGroup.length > 0) {
|
|
54
|
+
routeStore.addMiddleware(path, ...middlewareGroup);
|
|
55
|
+
}
|
|
56
|
+
return app;
|
|
57
|
+
},
|
|
58
|
+
get(path, ...handlers) {
|
|
59
|
+
(0, assert_1.assertNotLocked)(locked.current);
|
|
60
|
+
routeStore.addRoute('get', path, ...handlers);
|
|
61
|
+
return app;
|
|
62
|
+
},
|
|
63
|
+
post(path, ...handlers) {
|
|
64
|
+
(0, assert_1.assertNotLocked)(locked.current);
|
|
65
|
+
routeStore.addRoute('post', path, ...handlers);
|
|
66
|
+
return app;
|
|
67
|
+
},
|
|
68
|
+
put(path, ...handlers) {
|
|
69
|
+
(0, assert_1.assertNotLocked)(locked.current);
|
|
70
|
+
routeStore.addRoute('put', path, ...handlers);
|
|
71
|
+
return app;
|
|
72
|
+
},
|
|
73
|
+
patch(path, ...handlers) {
|
|
74
|
+
(0, assert_1.assertNotLocked)(locked.current);
|
|
75
|
+
routeStore.addRoute('patch', path, ...handlers);
|
|
76
|
+
return app;
|
|
77
|
+
},
|
|
78
|
+
delete(path, ...handlers) {
|
|
79
|
+
(0, assert_1.assertNotLocked)(locked.current);
|
|
80
|
+
routeStore.addRoute('delete', path, ...handlers);
|
|
81
|
+
return app;
|
|
82
|
+
},
|
|
83
|
+
head(path, ...handlers) {
|
|
84
|
+
(0, assert_1.assertNotLocked)(locked.current);
|
|
85
|
+
routeStore.addRoute('head', path, ...handlers);
|
|
86
|
+
return app;
|
|
87
|
+
},
|
|
88
|
+
options(path, ...handlers) {
|
|
89
|
+
(0, assert_1.assertNotLocked)(locked.current);
|
|
90
|
+
routeStore.addRoute('options', path, ...handlers);
|
|
91
|
+
return app;
|
|
92
|
+
},
|
|
93
|
+
all(path, ...handlers) {
|
|
94
|
+
(0, assert_1.assertNotLocked)(locked.current);
|
|
95
|
+
routeStore.addRoute('all', path, ...handlers);
|
|
96
|
+
return app;
|
|
97
|
+
},
|
|
98
|
+
listen(port, host, callback) {
|
|
99
|
+
let cb;
|
|
100
|
+
let p;
|
|
101
|
+
let h;
|
|
102
|
+
if (typeof port === 'function') {
|
|
103
|
+
cb = port;
|
|
104
|
+
p = undefined;
|
|
105
|
+
h = undefined;
|
|
106
|
+
}
|
|
107
|
+
else if (typeof host === 'function') {
|
|
108
|
+
cb = host;
|
|
109
|
+
p = port;
|
|
110
|
+
h = undefined;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
p = port;
|
|
114
|
+
h = host;
|
|
115
|
+
cb = callback;
|
|
116
|
+
}
|
|
117
|
+
locked.current = true;
|
|
118
|
+
const express = (0, engine_1.createExpressEngine)();
|
|
119
|
+
(0, populateExpress_1.populateExpressApp)(express, routeStore);
|
|
120
|
+
const fastify = (0, fastify_1.default)({
|
|
121
|
+
logger: false,
|
|
122
|
+
bodyLimit: 10 * 1024 * 1024, // 10MB; matches express.json({ limit: '10mb' }) for large payloads
|
|
123
|
+
});
|
|
124
|
+
const classified = (0, classify_1.classifyAll)(routeStore.getAll());
|
|
125
|
+
const runMiddleware = (_req, _res, next) => next();
|
|
126
|
+
(0, register_1.registerCompiledRoutes)(fastify, classified, runMiddleware);
|
|
127
|
+
// Wire Express 4-arg error middleware → Fastify error handler so next(err)/throw on the
|
|
128
|
+
// Fastify lane reaches it (parity with fast()). The error mw is excluded from the normal
|
|
129
|
+
// middleware chain (see compile.ts), so it only runs here.
|
|
130
|
+
const errorMiddleware = (0, errorHandler_1.findErrorMiddleware)(routeStore.getAll());
|
|
131
|
+
if (errorMiddleware) {
|
|
132
|
+
fastify.setErrorHandler((0, errorHandler_1.wrapErrorHandler)(errorMiddleware, (0, request_1.createRequestAdapter)(), response_1.adaptResponse));
|
|
133
|
+
}
|
|
134
|
+
(0, mount_1.mountExpress)(fastify, express);
|
|
135
|
+
const listenOpts = { port: p ?? 0, host: h ?? '0.0.0.0' };
|
|
136
|
+
const listenPromise = fastify.listen(listenOpts);
|
|
137
|
+
if (cb) {
|
|
138
|
+
listenPromise.then(() => cb(), (err) => cb?.(err));
|
|
139
|
+
}
|
|
140
|
+
return listenPromise.then(() => ({
|
|
141
|
+
close(closeCb) {
|
|
142
|
+
return fastify.close().then(() => closeCb?.(), (err) => closeCb?.(err));
|
|
143
|
+
},
|
|
144
|
+
address() {
|
|
145
|
+
return fastify.server?.address() ?? null;
|
|
146
|
+
},
|
|
147
|
+
}));
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
return app;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/runtime/lifecycle.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;AAwBH,8BA4JC;AAlLD,sDAA8B;AAG9B,8CAA8C;AAC9C,8CAAwD;AACxD,4CAAgD;AAChD,kDAA6D;AAC7D,uDAAuD;AACvD,4CAAkD;AAClD,iDAAuE;AACvE,yDAAmE;AACnE,2DAA6D;AAC7D,kDAA+C;AAC/C,wDAAsE;AACtE,wCAA8C;AAC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E,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;YACrD,CAAC;YACD,OAAO,aAAa,CAAC,IAAI,CACvB,GAAe,EAAE,CAAC,CAAC;gBACjB,KAAK,CAAC,OAAQ;oBACZ,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC1E,CAAC;gBACD,OAAO;oBACL,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,IAAI,CAAC;gBAC3C,CAAC;aACF,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Populate real Express app from RouteStore (all middleware + routes).
|
|
3
|
+
*/
|
|
4
|
+
import type { Application } from 'express';
|
|
5
|
+
import type { RouteStore } from '../app/RouteStore';
|
|
6
|
+
export declare function populateExpressApp(expressApp: Application, store: RouteStore): void;
|
|
7
|
+
//# sourceMappingURL=populateExpress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"populateExpress.d.ts","sourceRoot":"","sources":["../../src/runtime/populateExpress.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAgBnF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Populate real Express app from RouteStore (all middleware + routes).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.populateExpressApp = populateExpressApp;
|
|
7
|
+
const path_1 = require("../utils/path");
|
|
8
|
+
function populateExpressApp(expressApp, store) {
|
|
9
|
+
const entries = store.getAll();
|
|
10
|
+
for (const entry of entries) {
|
|
11
|
+
if (entry.type === 'middleware') {
|
|
12
|
+
const path = (0, path_1.normalizePath)(entry.path);
|
|
13
|
+
expressApp.use(path, ...entry.handlers);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const path = (0, path_1.normalizePath)(entry.path);
|
|
17
|
+
const method = entry.method === 'all' ? 'all' : entry.method;
|
|
18
|
+
if (method === 'all') {
|
|
19
|
+
expressApp.all(path, ...entry.handlers);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
expressApp[method](path, ...entry.handlers);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=populateExpress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"populateExpress.js","sourceRoot":"","sources":["../../src/runtime/populateExpress.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAMH,gDAgBC;AAlBD,wCAA8C;AAE9C,SAAgB,kBAAkB,CAAC,UAAuB,EAAE,KAAiB;IAC3E,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;IAC/B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAChC,MAAM,IAAI,GAAG,IAAA,oBAAa,EAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACvC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,GAAI,KAAK,CAAC,QAAgB,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GAAG,IAAA,oBAAa,EAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACvC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,KAAK,CAAC,MAA2E,CAAC;YACnI,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;gBACpB,UAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;YACnD,CAAC;iBAAM,CAAC;gBACL,UAAkB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Express-like types for the compatibility API.
|
|
3
|
+
* req, res, next - what users write against.
|
|
4
|
+
* Extended to cover Express 5.x response and request API used in adapters.
|
|
5
|
+
*/
|
|
6
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
7
|
+
/** Cookie options (Express-compatible shape). */
|
|
8
|
+
export interface CookieOptions {
|
|
9
|
+
maxAge?: number;
|
|
10
|
+
signed?: boolean;
|
|
11
|
+
expires?: Date;
|
|
12
|
+
httpOnly?: boolean;
|
|
13
|
+
path?: string;
|
|
14
|
+
domain?: string;
|
|
15
|
+
secure?: boolean;
|
|
16
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
17
|
+
}
|
|
18
|
+
export type ExpressRequest = IncomingMessage & {
|
|
19
|
+
body?: unknown;
|
|
20
|
+
query?: Record<string, string | string[]>;
|
|
21
|
+
params?: Record<string, string>;
|
|
22
|
+
url: string;
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
originalUrl: string;
|
|
25
|
+
path?: string;
|
|
26
|
+
method?: string;
|
|
27
|
+
headers?: IncomingMessage['headers'];
|
|
28
|
+
get(name: string): string | undefined;
|
|
29
|
+
header(name: string): string | undefined;
|
|
30
|
+
/** Trust proxy: protocol, ip, hostname, etc. (adapter-derived when possible). */
|
|
31
|
+
protocol?: string;
|
|
32
|
+
secure?: boolean;
|
|
33
|
+
ip?: string;
|
|
34
|
+
ips?: string[];
|
|
35
|
+
hostname?: string;
|
|
36
|
+
host?: string;
|
|
37
|
+
/** Accepts (Accept header); stub or parsed. */
|
|
38
|
+
accepts?(...types: string[]): string | false | string[];
|
|
39
|
+
acceptsCharsets?(...charsets: string[]): string | false | string[];
|
|
40
|
+
acceptsEncodings?(...encodings: string[]): string | false | string[];
|
|
41
|
+
acceptsLanguages?(...langs: string[]): string | false | string[];
|
|
42
|
+
is?(type: string): string | false;
|
|
43
|
+
range?(size: number, options?: {
|
|
44
|
+
combine?: boolean;
|
|
45
|
+
}): unknown;
|
|
46
|
+
xhr?: boolean;
|
|
47
|
+
fresh?: boolean;
|
|
48
|
+
stale?: boolean;
|
|
49
|
+
cookies?: Record<string, string>;
|
|
50
|
+
signedCookies?: Record<string, string>;
|
|
51
|
+
app?: unknown;
|
|
52
|
+
res?: ExpressResponse;
|
|
53
|
+
next?: unknown;
|
|
54
|
+
route?: unknown;
|
|
55
|
+
};
|
|
56
|
+
export type ExpressResponse = ServerResponse & {
|
|
57
|
+
status(code: number): ExpressResponse;
|
|
58
|
+
send(body?: unknown): ExpressResponse;
|
|
59
|
+
json(body?: unknown): ExpressResponse;
|
|
60
|
+
set(field: string | Record<string, string>, value?: string | string[]): ExpressResponse;
|
|
61
|
+
setHeader(name: string, value: string | number | string[]): ServerResponse;
|
|
62
|
+
removeHeader(name: string): ExpressResponse;
|
|
63
|
+
header(field: string | Record<string, string>, value?: string | string[]): ExpressResponse;
|
|
64
|
+
sendStatus(code: number): ExpressResponse;
|
|
65
|
+
links(links: Record<string, string>): ExpressResponse;
|
|
66
|
+
jsonp(body?: unknown): ExpressResponse;
|
|
67
|
+
type(type: string): ExpressResponse;
|
|
68
|
+
contentType(type: string): ExpressResponse;
|
|
69
|
+
format(obj: Record<string, (() => void) | (() => Promise<void>)>): ExpressResponse;
|
|
70
|
+
attachment(filename?: string): ExpressResponse;
|
|
71
|
+
append(field: string, value: string | string[]): ExpressResponse;
|
|
72
|
+
get(field: string): string | undefined;
|
|
73
|
+
getHeader(name: string): string | number | string[] | undefined;
|
|
74
|
+
clearCookie(name: string, options?: CookieOptions): ExpressResponse;
|
|
75
|
+
cookie(name: string, val: string | object, options?: CookieOptions): ExpressResponse;
|
|
76
|
+
location(url: string): ExpressResponse;
|
|
77
|
+
redirect(url: string): ExpressResponse;
|
|
78
|
+
redirect(status: number, url: string): ExpressResponse;
|
|
79
|
+
vary(field: string): ExpressResponse;
|
|
80
|
+
end(cb?: () => void): ServerResponse;
|
|
81
|
+
end(chunk: unknown, encoding?: BufferEncoding, cb?: () => void): ServerResponse;
|
|
82
|
+
/** View engine render (Express lane only; on Fastify lane we send 501 + dev warning). */
|
|
83
|
+
render?(view: string, locals?: Record<string, unknown>, callback?: (err: Error | null, html?: string) => void): ExpressResponse;
|
|
84
|
+
/** Per-request response locals (Express-compatible). */
|
|
85
|
+
locals: Record<string, unknown>;
|
|
86
|
+
headersSent: boolean;
|
|
87
|
+
app?: unknown;
|
|
88
|
+
req?: ExpressRequest;
|
|
89
|
+
charset?: string;
|
|
90
|
+
};
|
|
91
|
+
export type NextFunction = (err?: Error | unknown) => void;
|
|
92
|
+
export type ExpressMiddleware = (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => void | Promise<void>;
|
|
93
|
+
export type ExpressErrorMiddleware = (err: Error, req: ExpressRequest, res: ExpressResponse, next: NextFunction) => void | Promise<void>;
|
|
94
|
+
export type ExpressHandler = ExpressMiddleware | ExpressErrorMiddleware;
|
|
95
|
+
export declare const HTTP_METHODS: readonly ["get", "post", "put", "patch", "delete", "head", "options", "all"];
|
|
96
|
+
export type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
97
|
+
//# sourceMappingURL=express.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":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AK,GAAG,OAAO,KAAK,IAAI,CAAC;AAE3D,MAAM,MAAM,iBAAiB,GAAG,CAC9B,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,YAAY,KACf,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,MAAM,sBAAsB,GAAG,CACnC,GAAG,EAAE,KAAK,EACV,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,YAAY,KACf,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,MAAM,cAAc,GAAG,iBAAiB,GAAG,sBAAsB,CAAC;AAExE,eAAO,MAAM,YAAY,8EAEf,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Express-like types for the compatibility API.
|
|
4
|
+
* req, res, next - what users write against.
|
|
5
|
+
* Extended to cover Express 5.x response and request API used in adapters.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.HTTP_METHODS = void 0;
|
|
9
|
+
exports.HTTP_METHODS = [
|
|
10
|
+
'get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'all'
|
|
11
|
+
];
|
|
12
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/types/express.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA8GU,QAAA,YAAY,GAAG;IAC1B,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK;CACzD,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal compiler and runtime types.
|
|
3
|
+
* use() accepts Express Router so app.use("/api", router) type-checks (Express-compatible).
|
|
4
|
+
*/
|
|
5
|
+
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
6
|
+
import type { ExpressRequest, ExpressResponse, ExpressHandler } from "./express";
|
|
7
|
+
import type { Router } from "express";
|
|
8
|
+
/**
|
|
9
|
+
* Server-like object returned by app.listen().
|
|
10
|
+
* Express returns http.Server; we return a Promise that resolves to this,
|
|
11
|
+
* so you can call close() (and address()) like with Node's server.
|
|
12
|
+
*/
|
|
13
|
+
export interface ServerLike {
|
|
14
|
+
/** Stop accepting new connections. Same idea as http.Server#close(). */
|
|
15
|
+
close(callback?: (err?: Error) => void): Promise<void>;
|
|
16
|
+
/** Bound address after listen (port, address, family). Same shape as http.Server#address(). */
|
|
17
|
+
address(): ReturnType<import("node:net").Server["address"]>;
|
|
18
|
+
}
|
|
19
|
+
export type RouteEntry = {
|
|
20
|
+
type: "middleware";
|
|
21
|
+
path: string;
|
|
22
|
+
handlers: ExpressHandler[];
|
|
23
|
+
} | {
|
|
24
|
+
type: "route";
|
|
25
|
+
method: string;
|
|
26
|
+
path: string;
|
|
27
|
+
handlers: ExpressHandler[];
|
|
28
|
+
};
|
|
29
|
+
export type Lane = "fastify" | "express";
|
|
30
|
+
export type ClassifiedRoute = RouteEntry & {
|
|
31
|
+
lane: Lane;
|
|
32
|
+
/** If true, this route/middleware requires Express (unsafe for Fastify). */
|
|
33
|
+
expressRequired: boolean;
|
|
34
|
+
};
|
|
35
|
+
/** Handlers accepted in use(); includes Router so app.use("/api", router) type-checks. */
|
|
36
|
+
export type UseHandler = ExpressHandler | Router;
|
|
37
|
+
export interface ExpressLikeApp {
|
|
38
|
+
use(...handlers: UseHandler[]): this;
|
|
39
|
+
use(pathOrHandler: string | UseHandler, ...handlers: UseHandler[]): this;
|
|
40
|
+
get(path: string, ...handlers: ExpressHandler[]): this;
|
|
41
|
+
post(path: string, ...handlers: ExpressHandler[]): this;
|
|
42
|
+
put(path: string, ...handlers: ExpressHandler[]): this;
|
|
43
|
+
patch(path: string, ...handlers: ExpressHandler[]): this;
|
|
44
|
+
delete(path: string, ...handlers: ExpressHandler[]): this;
|
|
45
|
+
head(path: string, ...handlers: ExpressHandler[]): this;
|
|
46
|
+
options(path: string, ...handlers: ExpressHandler[]): this;
|
|
47
|
+
all(path: string, ...handlers: ExpressHandler[]): this;
|
|
48
|
+
/** Listen with optional port, host, and callback. Returns Promise<ServerLike> (Express returns http.Server; we are async). */
|
|
49
|
+
listen(port?: number, host?: string, callback?: (err?: Error) => void): Promise<ServerLike>;
|
|
50
|
+
listen(port: number, callback?: (err?: Error) => void): Promise<ServerLike>;
|
|
51
|
+
listen(callback?: (err?: Error) => void): Promise<ServerLike>;
|
|
52
|
+
}
|
|
53
|
+
export type RequestAdapter = (fastifyReq: FastifyRequest) => ExpressRequest;
|
|
54
|
+
export type ResponseAdapter = (fastifyReply: FastifyReply, fastifyReq: FastifyRequest) => ExpressResponse;
|
|
55
|
+
export interface RuntimeContext {
|
|
56
|
+
fastify: FastifyInstance;
|
|
57
|
+
expressApp: import("express").Application;
|
|
58
|
+
locked: boolean;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/types/internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,cAAc,EAEf,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAe,MAAM,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,wEAAwE;IACxE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAA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[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/utils/assert.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAIrD;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAE7D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Fail-fast helpers. No silent failures.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assertNotLocked = assertNotLocked;
|
|
7
|
+
exports.failUnsupportedFeature = failUnsupportedFeature;
|
|
8
|
+
const ROUTE_LOCKED_MSG = 'Cannot add routes or middleware after listen(). Routes are immutable.';
|
|
9
|
+
function assertNotLocked(locked) {
|
|
10
|
+
if (locked) {
|
|
11
|
+
throw new Error(ROUTE_LOCKED_MSG);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function failUnsupportedFeature(feature) {
|
|
15
|
+
throw new Error(`${feature} is not supported. Fail loudly.`);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/utils/assert.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAIH,0CAIC;AAED,wDAEC;AAVD,MAAM,gBAAgB,GAAG,uEAAuE,CAAC;AAEjG,SAAgB,eAAe,CAAC,MAAe;IAC7C,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED,SAAgB,sBAAsB,CAAC,OAAe;IACpD,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,iCAAiC,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unsafe middleware detection.
|
|
3
|
+
* If unsure → Express lane. Never silently downgrade.
|
|
4
|
+
*/
|
|
5
|
+
import type { ExpressHandler } from '../types/express';
|
|
6
|
+
/**
|
|
7
|
+
* Returns true if the middleware is known to require Express (streams, multipart, etc.).
|
|
8
|
+
*/
|
|
9
|
+
export declare function isExpressRequired(fn: ExpressHandler): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the middleware is safe to run in Fastify (no streams, no prototype mutation).
|
|
12
|
+
*/
|
|
13
|
+
export declare function isFastifySafe(fn: ExpressHandler): boolean;
|
|
14
|
+
//# sourceMappingURL=detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/utils/detect.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA2BvD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAiB7D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAEzD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unsafe middleware detection.
|
|
4
|
+
* If unsure → Express lane. Never silently downgrade.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.isExpressRequired = isExpressRequired;
|
|
8
|
+
exports.isFastifySafe = isFastifySafe;
|
|
9
|
+
const unwrap_1 = require("./unwrap");
|
|
10
|
+
const UNSAFE_NAMES = new Set([
|
|
11
|
+
'multer',
|
|
12
|
+
'upload',
|
|
13
|
+
'storage.upload',
|
|
14
|
+
'formidable',
|
|
15
|
+
'busboy',
|
|
16
|
+
'multipart',
|
|
17
|
+
// Express body parsers that read the raw request stream. On the Fastify lane the body stream
|
|
18
|
+
// is already consumed and there is no parser for these content types, so they must run on the
|
|
19
|
+
// Express lane. NOTE: express.json()'s `jsonParser` is intentionally NOT here — it is mapped to
|
|
20
|
+
// Fastify's native JSON parser (see express/middleware.ts) and stays on the fast lane.
|
|
21
|
+
'urlencodedparser', // express.urlencoded()
|
|
22
|
+
'rawparser', // express.raw()
|
|
23
|
+
'textparser', // express.text()
|
|
24
|
+
]);
|
|
25
|
+
const UNSAFE_PATTERNS = [
|
|
26
|
+
/\.pipe\s*\(/,
|
|
27
|
+
/req\.on\s*\(\s*['"]data['"]/,
|
|
28
|
+
/req\.on\s*\(\s*['"]end['"]/,
|
|
29
|
+
/multipart\/form-data/,
|
|
30
|
+
/formidable|busboy|multer/,
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Returns true if the middleware is known to require Express (streams, multipart, etc.).
|
|
34
|
+
*/
|
|
35
|
+
function isExpressRequired(fn) {
|
|
36
|
+
if (typeof fn !== 'function')
|
|
37
|
+
return true;
|
|
38
|
+
// Unwrap APM wrappers (OpenTelemetry/Sentry) so body parsers/multer/etc. are recognized even
|
|
39
|
+
// when an instrumentation library has wrapped them (otherwise fn.name is e.g. "patched").
|
|
40
|
+
const target = (0, unwrap_1.unwrapHandler)(fn);
|
|
41
|
+
if (typeof target !== 'function')
|
|
42
|
+
return true;
|
|
43
|
+
const s = target.name || '';
|
|
44
|
+
const str = target.toString();
|
|
45
|
+
const nameLower = s.toLowerCase();
|
|
46
|
+
if (UNSAFE_NAMES.has(nameLower))
|
|
47
|
+
return true;
|
|
48
|
+
for (const name of UNSAFE_NAMES) {
|
|
49
|
+
if (nameLower.includes(name) || str.includes(name))
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
for (const re of UNSAFE_PATTERNS) {
|
|
53
|
+
if (re.test(str))
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns true if the middleware is safe to run in Fastify (no streams, no prototype mutation).
|
|
60
|
+
*/
|
|
61
|
+
function isFastifySafe(fn) {
|
|
62
|
+
return !isExpressRequired(fn);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=detect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/utils/detect.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAgCH,8CAiBC;AAKD,sCAEC;AArDD,qCAAyC;AAEzC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,QAAQ;IACR,QAAQ;IACR,gBAAgB;IAChB,YAAY;IACZ,QAAQ;IACR,WAAW;IACX,6FAA6F;IAC7F,8FAA8F;IAC9F,gGAAgG;IAChG,uFAAuF;IACvF,kBAAkB,EAAE,uBAAuB;IAC3C,WAAW,EAAE,gBAAgB;IAC7B,YAAY,EAAE,iBAAiB;CAChC,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG;IACtB,aAAa;IACb,6BAA6B;IAC7B,4BAA4B;IAC5B,sBAAsB;IACtB,0BAA0B;CAC3B,CAAC;AAEF;;GAEG;AACH,SAAgB,iBAAiB,CAAC,EAAkB;IAClD,IAAI,OAAO,EAAE,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IAC1C,6FAA6F;IAC7F,0FAA0F;IAC1F,MAAM,MAAM,GAAG,IAAA,sBAAa,EAAC,EAAE,CAAmB,CAAC;IACnD,IAAI,OAAO,MAAM,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IAC9C,MAAM,CAAC,GAAI,MAAuC,CAAC,IAAI,IAAI,EAAE,CAAC;IAC9D,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC9B,MAAM,SAAS,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAClC,IAAI,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7C,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;IAClE,CAAC;IACD,KAAK,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC;QACjC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;IAChC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,EAAkB;IAC9C,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Max listeners for request/response and socket.
|
|
3
|
+
*
|
|
4
|
+
* Node's default EventEmitter max listeners is 10. In a plain Express or
|
|
5
|
+
* Fastify app that's usually fine, and neither framework changes it.
|
|
6
|
+
*
|
|
7
|
+
* In express-fastify-runtime we run **Express-style middleware on top of
|
|
8
|
+
* Fastify's request/reply**, so a single response/socket can legitimately have
|
|
9
|
+
* many listeners (our finish waiter, morgan, user middleware, etc.).
|
|
10
|
+
*
|
|
11
|
+
* Rather than trying to guess a safe upper bound (we already saw 32 was not
|
|
12
|
+
* enough under load), we set the limit to **Infinity (unlimited)** for the
|
|
13
|
+
* specific response/socket objects we control so Node does not emit
|
|
14
|
+
* MaxListenersExceededWarning for this intentional pattern.
|
|
15
|
+
*/
|
|
16
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
17
|
+
/** Default max listeners per response and per socket (Infinity = unlimited). */
|
|
18
|
+
export declare const DEFAULT_MAX_LISTENERS: number;
|
|
19
|
+
/**
|
|
20
|
+
* Raise (or remove) the max-listener limit on the raw response and the
|
|
21
|
+
* request's socket so multiple listeners (our finish waiter, morgan, user
|
|
22
|
+
* middleware, etc.) do not trigger MaxListenersExceededWarning.
|
|
23
|
+
*
|
|
24
|
+
* Call at the start of each request (Fastify preHandler or Express lane
|
|
25
|
+
* notFoundHandler).
|
|
26
|
+
*/
|
|
27
|
+
export declare function applyMaxListeners(rawReq: IncomingMessage, rawRes: ServerResponse, limit?: number): void;
|
|
28
|
+
//# sourceMappingURL=maxListeners.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maxListeners.d.ts","sourceRoot":"","sources":["../../src/utils/maxListeners.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,QAAW,CAAC;AAE9C;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,cAAc,EACtB,KAAK,GAAE,MAA8B,GACpC,IAAI,CAiBN"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Max listeners for request/response and socket.
|
|
4
|
+
*
|
|
5
|
+
* Node's default EventEmitter max listeners is 10. In a plain Express or
|
|
6
|
+
* Fastify app that's usually fine, and neither framework changes it.
|
|
7
|
+
*
|
|
8
|
+
* In express-fastify-runtime we run **Express-style middleware on top of
|
|
9
|
+
* Fastify's request/reply**, so a single response/socket can legitimately have
|
|
10
|
+
* many listeners (our finish waiter, morgan, user middleware, etc.).
|
|
11
|
+
*
|
|
12
|
+
* Rather than trying to guess a safe upper bound (we already saw 32 was not
|
|
13
|
+
* enough under load), we set the limit to **Infinity (unlimited)** for the
|
|
14
|
+
* specific response/socket objects we control so Node does not emit
|
|
15
|
+
* MaxListenersExceededWarning for this intentional pattern.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.DEFAULT_MAX_LISTENERS = void 0;
|
|
19
|
+
exports.applyMaxListeners = applyMaxListeners;
|
|
20
|
+
/** Default max listeners per response and per socket (Infinity = unlimited). */
|
|
21
|
+
exports.DEFAULT_MAX_LISTENERS = Infinity;
|
|
22
|
+
/**
|
|
23
|
+
* Raise (or remove) the max-listener limit on the raw response and the
|
|
24
|
+
* request's socket so multiple listeners (our finish waiter, morgan, user
|
|
25
|
+
* middleware, etc.) do not trigger MaxListenersExceededWarning.
|
|
26
|
+
*
|
|
27
|
+
* Call at the start of each request (Fastify preHandler or Express lane
|
|
28
|
+
* notFoundHandler).
|
|
29
|
+
*/
|
|
30
|
+
function applyMaxListeners(rawReq, rawRes, limit = exports.DEFAULT_MAX_LISTENERS) {
|
|
31
|
+
// Hot path: when limit is Infinity (default), skip getMaxListeners (saves two calls per request).
|
|
32
|
+
if (typeof rawRes.setMaxListeners === "function") {
|
|
33
|
+
if (limit === Infinity) {
|
|
34
|
+
rawRes.setMaxListeners(Infinity);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
rawRes.setMaxListeners(Math.max(rawRes.getMaxListeners?.() ?? 10, limit));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const socket = rawReq?.socket;
|
|
41
|
+
if (socket && typeof socket.setMaxListeners === "function") {
|
|
42
|
+
if (limit === Infinity) {
|
|
43
|
+
socket.setMaxListeners(Infinity);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
socket.setMaxListeners(Math.max(socket.getMaxListeners?.() ?? 10, limit));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=maxListeners.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maxListeners.js","sourceRoot":"","sources":["../../src/utils/maxListeners.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAeH,8CAqBC;AAhCD,gFAAgF;AACnE,QAAA,qBAAqB,GAAG,QAAQ,CAAC;AAE9C;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAC/B,MAAuB,EACvB,MAAsB,EACtB,QAAgB,6BAAqB;IAErC,kGAAkG;IAClG,IAAI,OAAO,MAAM,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;QACjD,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvB,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC;IAC9B,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;QAC3D,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvB,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patch the router package's Layer so that the path passed to Layer(path, options, fn)
|
|
3
|
+
* is stored on the instance as _path. This allows us to flatten routers that use
|
|
4
|
+
* router.use(path, fn) by reading layer._path at compile time.
|
|
5
|
+
*
|
|
6
|
+
* We run once when the package is loaded (startup only; no per-request cost).
|
|
7
|
+
* We patch from our package's resolution context and also from process.cwd() so
|
|
8
|
+
* that when the app lives in another package (e.g. workspace or app with its own
|
|
9
|
+
* node_modules), the same router copy the app uses gets patched.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=patchRouterLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patchRouterLayer.d.ts","sourceRoot":"","sources":["../../src/utils/patchRouterLayer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAmGH,OAAO,EAAE,CAAC"}
|