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.
Files changed (134) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +326 -0
  3. package/changelog/README.md +5 -0
  4. package/changelog/log-2025-02-07.md +10 -0
  5. package/changelog/log-2026-06-25.md +151 -0
  6. package/dist/app/ExpressLikeApp.d.ts +9 -0
  7. package/dist/app/ExpressLikeApp.d.ts.map +1 -0
  8. package/dist/app/ExpressLikeApp.js +64 -0
  9. package/dist/app/ExpressLikeApp.js.map +1 -0
  10. package/dist/app/RouteStore.d.ts +17 -0
  11. package/dist/app/RouteStore.d.ts.map +1 -0
  12. package/dist/app/RouteStore.js +43 -0
  13. package/dist/app/RouteStore.js.map +1 -0
  14. package/dist/app/classify.d.ts +8 -0
  15. package/dist/app/classify.d.ts.map +1 -0
  16. package/dist/app/classify.js +25 -0
  17. package/dist/app/classify.js.map +1 -0
  18. package/dist/app/compile.d.ts +25 -0
  19. package/dist/app/compile.d.ts.map +1 -0
  20. package/dist/app/compile.js +195 -0
  21. package/dist/app/compile.js.map +1 -0
  22. package/dist/app/flattenRouter.d.ts +51 -0
  23. package/dist/app/flattenRouter.d.ts.map +1 -0
  24. package/dist/app/flattenRouter.js +126 -0
  25. package/dist/app/flattenRouter.js.map +1 -0
  26. package/dist/app/introspectExpress.d.ts +29 -0
  27. package/dist/app/introspectExpress.d.ts.map +1 -0
  28. package/dist/app/introspectExpress.js +60 -0
  29. package/dist/app/introspectExpress.js.map +1 -0
  30. package/dist/examples/auth.d.ts +6 -0
  31. package/dist/examples/auth.d.ts.map +1 -0
  32. package/dist/examples/auth.js +26 -0
  33. package/dist/examples/auth.js.map +1 -0
  34. package/dist/examples/logging.d.ts +6 -0
  35. package/dist/examples/logging.d.ts.map +1 -0
  36. package/dist/examples/logging.js +25 -0
  37. package/dist/examples/logging.js.map +1 -0
  38. package/dist/examples/uploads.d.ts +6 -0
  39. package/dist/examples/uploads.d.ts.map +1 -0
  40. package/dist/examples/uploads.js +21 -0
  41. package/dist/examples/uploads.js.map +1 -0
  42. package/dist/express/engine.d.ts +6 -0
  43. package/dist/express/engine.d.ts.map +1 -0
  44. package/dist/express/engine.js +14 -0
  45. package/dist/express/engine.js.map +1 -0
  46. package/dist/express/middleware.d.ts +15 -0
  47. package/dist/express/middleware.d.ts.map +1 -0
  48. package/dist/express/middleware.js +32 -0
  49. package/dist/express/middleware.js.map +1 -0
  50. package/dist/express/mount.d.ts +35 -0
  51. package/dist/express/mount.d.ts.map +1 -0
  52. package/dist/express/mount.js +78 -0
  53. package/dist/express/mount.js.map +1 -0
  54. package/dist/fastify/adapters/middleware.d.ts +8 -0
  55. package/dist/fastify/adapters/middleware.d.ts.map +1 -0
  56. package/dist/fastify/adapters/middleware.js +29 -0
  57. package/dist/fastify/adapters/middleware.js.map +1 -0
  58. package/dist/fastify/adapters/request.d.ts +19 -0
  59. package/dist/fastify/adapters/request.d.ts.map +1 -0
  60. package/dist/fastify/adapters/request.js +258 -0
  61. package/dist/fastify/adapters/request.js.map +1 -0
  62. package/dist/fastify/adapters/response.d.ts +19 -0
  63. package/dist/fastify/adapters/response.d.ts.map +1 -0
  64. package/dist/fastify/adapters/response.js +667 -0
  65. package/dist/fastify/adapters/response.js.map +1 -0
  66. package/dist/fastify/register.d.ts +12 -0
  67. package/dist/fastify/register.d.ts.map +1 -0
  68. package/dist/fastify/register.js +15 -0
  69. package/dist/fastify/register.js.map +1 -0
  70. package/dist/index.d.ts +13 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +18 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/runtime/decorators.d.ts +7 -0
  75. package/dist/runtime/decorators.d.ts.map +1 -0
  76. package/dist/runtime/decorators.js +17 -0
  77. package/dist/runtime/decorators.js.map +1 -0
  78. package/dist/runtime/errorHandler.d.ts +13 -0
  79. package/dist/runtime/errorHandler.d.ts.map +1 -0
  80. package/dist/runtime/errorHandler.js +95 -0
  81. package/dist/runtime/errorHandler.js.map +1 -0
  82. package/dist/runtime/expressLane.d.ts +40 -0
  83. package/dist/runtime/expressLane.d.ts.map +1 -0
  84. package/dist/runtime/expressLane.js +71 -0
  85. package/dist/runtime/expressLane.js.map +1 -0
  86. package/dist/runtime/fast.d.ts +43 -0
  87. package/dist/runtime/fast.d.ts.map +1 -0
  88. package/dist/runtime/fast.js +150 -0
  89. package/dist/runtime/fast.js.map +1 -0
  90. package/dist/runtime/lifecycle.d.ts +10 -0
  91. package/dist/runtime/lifecycle.d.ts.map +1 -0
  92. package/dist/runtime/lifecycle.js +152 -0
  93. package/dist/runtime/lifecycle.js.map +1 -0
  94. package/dist/runtime/populateExpress.d.ts +7 -0
  95. package/dist/runtime/populateExpress.d.ts.map +1 -0
  96. package/dist/runtime/populateExpress.js +27 -0
  97. package/dist/runtime/populateExpress.js.map +1 -0
  98. package/dist/types/express.d.ts +97 -0
  99. package/dist/types/express.d.ts.map +1 -0
  100. package/dist/types/express.js +12 -0
  101. package/dist/types/express.js.map +1 -0
  102. package/dist/types/internal.d.ts +60 -0
  103. package/dist/types/internal.d.ts.map +1 -0
  104. package/dist/types/internal.js +7 -0
  105. package/dist/types/internal.js.map +1 -0
  106. package/dist/utils/assert.d.ts +6 -0
  107. package/dist/utils/assert.d.ts.map +1 -0
  108. package/dist/utils/assert.js +17 -0
  109. package/dist/utils/assert.js.map +1 -0
  110. package/dist/utils/detect.d.ts +14 -0
  111. package/dist/utils/detect.d.ts.map +1 -0
  112. package/dist/utils/detect.js +64 -0
  113. package/dist/utils/detect.js.map +1 -0
  114. package/dist/utils/maxListeners.d.ts +28 -0
  115. package/dist/utils/maxListeners.d.ts.map +1 -0
  116. package/dist/utils/maxListeners.js +50 -0
  117. package/dist/utils/maxListeners.js.map +1 -0
  118. package/dist/utils/patchRouterLayer.d.ts +12 -0
  119. package/dist/utils/patchRouterLayer.d.ts.map +1 -0
  120. package/dist/utils/patchRouterLayer.js +96 -0
  121. package/dist/utils/patchRouterLayer.js.map +1 -0
  122. package/dist/utils/path.d.ts +6 -0
  123. package/dist/utils/path.d.ts.map +1 -0
  124. package/dist/utils/path.js +23 -0
  125. package/dist/utils/path.js.map +1 -0
  126. package/dist/utils/runtimeLogger.d.ts +15 -0
  127. package/dist/utils/runtimeLogger.d.ts.map +1 -0
  128. package/dist/utils/runtimeLogger.js +28 -0
  129. package/dist/utils/runtimeLogger.js.map +1 -0
  130. package/dist/utils/unwrap.d.ts +12 -0
  131. package/dist/utils/unwrap.d.ts.map +1 -0
  132. package/dist/utils/unwrap.js +24 -0
  133. package/dist/utils/unwrap.js.map +1 -0
  134. package/package.json +94 -0
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ /**
3
+ * Patch the router package's Layer so that the path passed to Layer(path, options, fn)
4
+ * is stored on the instance as _path. This allows us to flatten routers that use
5
+ * router.use(path, fn) by reading layer._path at compile time.
6
+ *
7
+ * We run once when the package is loaded (startup only; no per-request cost).
8
+ * We patch from our package's resolution context and also from process.cwd() so
9
+ * that when the app lives in another package (e.g. workspace or app with its own
10
+ * node_modules), the same router copy the app uses gets patched.
11
+ */
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ const node_module_1 = require("node:module");
17
+ const node_path_1 = __importDefault(require("node:path"));
18
+ const requireFromPkg = (0, node_module_1.createRequire)(__filename);
19
+ const thisDir = __dirname;
20
+ function patchLayerModule(layerModulePath) {
21
+ const layerModule = requireFromPkg.cache[layerModulePath];
22
+ if (!layerModule)
23
+ return;
24
+ const OriginalLayer = layerModule.exports;
25
+ if (!OriginalLayer || OriginalLayer._pathPatched)
26
+ return;
27
+ const PatchedLayer = function (pathArg, options, fn) {
28
+ if (!(this instanceof OriginalLayer)) {
29
+ return new OriginalLayer(pathArg, options, fn);
30
+ }
31
+ OriginalLayer.call(this, pathArg, options, fn);
32
+ const layerInstance = this;
33
+ if (typeof pathArg === "string") {
34
+ layerInstance._path = pathArg;
35
+ }
36
+ else if (pathArg instanceof RegExp) {
37
+ layerInstance._path = undefined;
38
+ }
39
+ else if (Array.isArray(pathArg)) {
40
+ layerInstance._path = undefined;
41
+ }
42
+ };
43
+ PatchedLayer.prototype = OriginalLayer.prototype;
44
+ PatchedLayer._pathPatched = true;
45
+ layerModule.exports = PatchedLayer;
46
+ }
47
+ const patchedPaths = new Set();
48
+ function tryPatchModule(specifier, basePath) {
49
+ try {
50
+ const layerModulePath = requireFromPkg.resolve(specifier, { paths: [basePath] });
51
+ if (patchedPaths.has(layerModulePath))
52
+ return;
53
+ patchedPaths.add(layerModulePath);
54
+ requireFromPkg(layerModulePath);
55
+ patchLayerModule(layerModulePath);
56
+ }
57
+ catch {
58
+ // module not available from this path
59
+ }
60
+ }
61
+ function tryPatchFrom(basePath) {
62
+ // Express 5 uses the standalone `router` package; Express 4 bundles its Layer inside express.
63
+ // Both have a Layer(path, options, fn) constructor, so the same patch records _path on each.
64
+ tryPatchModule("router/lib/layer", basePath);
65
+ tryPatchModule("express/lib/router/layer", basePath);
66
+ }
67
+ try {
68
+ tryPatchFrom(thisDir);
69
+ const cwd = typeof process !== "undefined" ? process.cwd() : "";
70
+ if (cwd && node_path_1.default.resolve(cwd) !== node_path_1.default.resolve(thisDir))
71
+ tryPatchFrom(cwd);
72
+ // Patch from the main script's directory (CJS entry) so we patch the same router the app uses
73
+ const main = requireFromPkg.main;
74
+ const mainDir = main && typeof main.filename === "string"
75
+ ? node_path_1.default.dirname(main.filename)
76
+ : "";
77
+ if (mainDir && node_path_1.default.resolve(mainDir) !== node_path_1.default.resolve(thisDir))
78
+ tryPatchFrom(mainDir);
79
+ // When entry is ESM, require.main is often undefined; use process.argv[1] so we still patch from the entry script's context
80
+ const entryScript = typeof process !== "undefined" &&
81
+ process.argv[1] &&
82
+ node_path_1.default.isAbsolute(process.argv[1])
83
+ ? process.argv[1]
84
+ : process.argv[1]
85
+ ? node_path_1.default.resolve(cwd || ".", process.argv[1])
86
+ : "";
87
+ const entryDir = entryScript ? node_path_1.default.dirname(entryScript) : "";
88
+ if (entryDir &&
89
+ node_path_1.default.resolve(entryDir) !== node_path_1.default.resolve(thisDir) &&
90
+ node_path_1.default.resolve(entryDir) !== node_path_1.default.resolve(mainDir))
91
+ tryPatchFrom(entryDir);
92
+ }
93
+ catch {
94
+ // router not available or different structure; flattening will fall back to express lane for routers with middleware
95
+ }
96
+ //# sourceMappingURL=patchRouterLayer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patchRouterLayer.js","sourceRoot":"","sources":["../../src/utils/patchRouterLayer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;AAEH,6CAA4C;AAC5C,0DAA6B;AAE7B,MAAM,cAAc,GAAG,IAAA,2BAAa,EAAC,UAAU,CAAC,CAAC;AACjD,MAAM,OAAO,GAAG,SAAS,CAAC;AAQ1B,SAAS,gBAAgB,CAAC,eAAuB;IAC/C,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAC1D,IAAI,CAAC,WAAW;QAAE,OAAO;IACzB,MAAM,aAAa,GAAG,WAAW,CAAC,OAEjC,CAAC;IACF,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,YAAY;QAAE,OAAO;IAEzD,MAAM,YAAY,GAAG,UAEnB,OAAiD,EACjD,OAAiE,EACjE,EAAuD;QAEvD,IAAI,CAAC,CAAC,IAAI,YAAa,aAAqB,CAAC,EAAE,CAAC;YAC9C,OAAO,IAAK,aAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;QAC1D,CAAC;QACA,aAAqB,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;QACxD,MAAM,aAAa,GAAG,IAA0B,CAAC;QACjD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,aAAa,C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,mBAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QAEhD,YAAY,CAAC,QAAQ,CAAC,CAAC;AAC3B,CAAC;AAAC,MAAM,CAAC;IACP,qHAAqH;AACvH,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Path normalization for route matching.
3
+ */
4
+ export declare function normalizePath(path: string): string;
5
+ export declare function joinPath(prefix: string, path: string): string;
6
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIlD;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAM7D"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * Path normalization for route matching.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.normalizePath = normalizePath;
7
+ exports.joinPath = joinPath;
8
+ function normalizePath(path) {
9
+ if (!path || path === '/')
10
+ return '/';
11
+ const trimmed = path.replace(/\/+/g, '/').replace(/\/$/, '') || '/';
12
+ return trimmed.startsWith('/') ? trimmed : '/' + trimmed;
13
+ }
14
+ function joinPath(prefix, path) {
15
+ const a = normalizePath(prefix);
16
+ const b = normalizePath(path);
17
+ if (a === '/')
18
+ return b;
19
+ if (b === '/')
20
+ return a;
21
+ return a + b;
22
+ }
23
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,sCAIC;AAED,4BAMC;AAZD,SAAgB,aAAa,CAAC,IAAY;IACxC,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,GAAG,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;IACpE,OAAO,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,OAAO,CAAC;AAC3D,CAAC;AAED,SAAgB,QAAQ,CAAC,MAAc,EAAE,IAAY;IACnD,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK,GAAG;QAAE,OAAO,CAAC,CAAC;IACxB,IAAI,CAAC,KAAK,GAAG;QAAE,OAAO,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Lightweight runtime logger for dev-only warnings when we fall back to Express lane.
3
+ * No dependency on pino; uses console in development.
4
+ */
5
+ export interface RuntimeLogger {
6
+ /** Call when a feature is unsupported and we fall back to Express lane. */
7
+ warnDowngrade(feature: string): void;
8
+ }
9
+ /**
10
+ * Create a runtime logger. Only logs when dev is true or NODE_ENV !== 'production'.
11
+ */
12
+ export declare function createRuntimeLogger(options?: {
13
+ dev?: boolean;
14
+ }): RuntimeLogger;
15
+ //# sourceMappingURL=runtimeLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimeLogger.d.ts","sourceRoot":"","sources":["../../src/utils/runtimeLogger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAOD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,aAAa,CAS9E"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * Lightweight runtime logger for dev-only warnings when we fall back to Express lane.
4
+ * No dependency on pino; uses console in development.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.createRuntimeLogger = createRuntimeLogger;
8
+ const PREFIX = '[express-fastify-runtime]';
9
+ const FALLBACK_MSG = 'is not supported fully yet, downgrading to express pattern (create an issue if this is something you would like express-runtime to support)';
10
+ function isDev(dev) {
11
+ if (typeof dev === 'boolean')
12
+ return dev;
13
+ return process.env.NODE_ENV !== 'production';
14
+ }
15
+ /**
16
+ * Create a runtime logger. Only logs when dev is true or NODE_ENV !== 'production'.
17
+ */
18
+ function createRuntimeLogger(options) {
19
+ const active = isDev(options?.dev);
20
+ return {
21
+ warnDowngrade(feature) {
22
+ if (active) {
23
+ console.warn(`${PREFIX} ${feature} ${FALLBACK_MSG}`);
24
+ }
25
+ },
26
+ };
27
+ }
28
+ //# sourceMappingURL=runtimeLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimeLogger.js","sourceRoot":"","sources":["../../src/utils/runtimeLogger.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAmBH,kDASC;AA1BD,MAAM,MAAM,GAAG,2BAA2B,CAAC;AAC3C,MAAM,YAAY,GAChB,6IAA6I,CAAC;AAOhJ,SAAS,KAAK,CAAC,GAAa;IAC1B,IAAI,OAAO,GAAG,KAAK,SAAS;QAAE,OAAO,GAAG,CAAC;IACzC,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,OAA2B;IAC7D,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO;QACL,aAAa,CAAC,OAAe;YAC3B,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,OAAO,IAAI,YAAY,EAAE,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Unwrap instrumentation wrappers to reach the original handler.
3
+ *
4
+ * APMs (OpenTelemetry / Sentry, via `shimmer`) wrap Express handlers, setting `wrapped.__original`
5
+ * to the real function (and `wrapped.__wrapped = true`); the wrapper's own `.name` becomes
6
+ * something like "patched". Our middleware identity checks (express.json, urlencoded, multer, …)
7
+ * inspect the function name/source, so they must look through the wrapper — otherwise a wrapped
8
+ * `jsonParser` isn't recognized, runs on the Fastify lane, and tries to read the already-consumed
9
+ * request stream ("argument stream must be a stream"). Follows the `__original` chain defensively.
10
+ */
11
+ export declare function unwrapHandler<T>(fn: T): T;
12
+ //# sourceMappingURL=unwrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwrap.d.ts","sourceRoot":"","sources":["../../src/utils/unwrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAWzC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unwrapHandler = unwrapHandler;
4
+ /**
5
+ * Unwrap instrumentation wrappers to reach the original handler.
6
+ *
7
+ * APMs (OpenTelemetry / Sentry, via `shimmer`) wrap Express handlers, setting `wrapped.__original`
8
+ * to the real function (and `wrapped.__wrapped = true`); the wrapper's own `.name` becomes
9
+ * something like "patched". Our middleware identity checks (express.json, urlencoded, multer, …)
10
+ * inspect the function name/source, so they must look through the wrapper — otherwise a wrapped
11
+ * `jsonParser` isn't recognized, runs on the Fastify lane, and tries to read the already-consumed
12
+ * request stream ("argument stream must be a stream"). Follows the `__original` chain defensively.
13
+ */
14
+ function unwrapHandler(fn) {
15
+ let cur = fn;
16
+ let depth = 0;
17
+ while (typeof cur === "function" &&
18
+ typeof cur.__original === "function" &&
19
+ depth++ < 16) {
20
+ cur = cur.__original;
21
+ }
22
+ return cur;
23
+ }
24
+ //# sourceMappingURL=unwrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwrap.js","sourceRoot":"","sources":["../../src/utils/unwrap.ts"],"names":[],"mappings":";;AAUA,sCAWC;AArBD;;;;;;;;;GASG;AACH,SAAgB,aAAa,CAAI,EAAK;IACpC,IAAI,GAAG,GAAY,EAAE,CAAC;IACtB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OACE,OAAO,GAAG,KAAK,UAAU;QACzB,OAAQ,GAAgC,CAAC,UAAU,KAAK,UAAU;QAClE,KAAK,EAAE,GAAG,EAAE,EACZ,CAAC;QACD,GAAG,GAAI,GAAgC,CAAC,UAAU,CAAC;IACrD,CAAC;IACD,OAAO,GAAQ,CAAC;AAClB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "express-fastify-runtime",
3
+ "version": "0.1.0",
4
+ "description": "Run Express apps on Fastify safely, faster, without code changes",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/John-Daniels/express-fastify-runtime.git"
22
+ },
23
+ "keywords": [
24
+ "express",
25
+ "fastify",
26
+ "runtime",
27
+ "compatibility",
28
+ "middleware",
29
+ "migration"
30
+ ],
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE",
35
+ "changelog"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsc",
39
+ "test": "npm run build && node --test test/*/*.test.js",
40
+ "test:unit": "npm run build && node --test test/unit/*.test.js",
41
+ "test:integration": "npm run build && node --test test/integration/*.test.js",
42
+ "test:compat": "npm run build && node --test test/compat/*.test.js",
43
+ "benchmark": "npm run build && node benchmarks/summary/report.js",
44
+ "benchmark:smoke": "node benchmarks/summary/run-fast.js",
45
+ "benchmark:servers": "npm run build && node benchmarks/servers/run.js",
46
+ "benchmark:routes": "node benchmarks/server-routes/run.js",
47
+ "benchmark:json": "node benchmarks/json-db-test/run.js",
48
+ "benchmark:lowdb": "node benchmarks/low-db-test/run.js",
49
+ "benchmark:middleware": "node benchmarks/middleware-stack/run.js",
50
+ "benchmark:auth": "node benchmarks/auth/run.js",
51
+ "benchmark:crud": "node benchmarks/crud-todo/run.js",
52
+ "benchmark:payloads": "node benchmarks/payloads/run.js",
53
+ "benchmark:uploads": "node benchmarks/uploads/run.js",
54
+ "benchmark:fast": "node benchmarks/fast-scenarios/run.js",
55
+ "benchmark:fast-vs-fastify": "node benchmarks/fast-vs-fastify/run.js",
56
+ "benchmark:table": "npm run build && node benchmarks/table/run.js",
57
+ "prepublishOnly": "npm run build"
58
+ },
59
+ "dependencies": {
60
+ "accepts": "^1.3.8",
61
+ "encodeurl": "^2.0.0",
62
+ "fastify": "^5.8.5",
63
+ "range-parser": "^1.2.1",
64
+ "type-is": "^2.0.1"
65
+ },
66
+ "peerDependencies": {
67
+ "express": "^4.18.0 || ^5.0.0"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "express": {
71
+ "optional": false
72
+ }
73
+ },
74
+ "devDependencies": {
75
+ "@fastify/formbody": "^8.0.2",
76
+ "@fastify/helmet": "^13.0.2",
77
+ "@fastify/jwt": "^10.0.0",
78
+ "@fastify/multipart": "^9.4.0",
79
+ "@types/express": "^5.0.0",
80
+ "@types/morgan": "^1.9.10",
81
+ "@types/node": "^22.0.0",
82
+ "autocannon": "^7.14.0",
83
+ "ejs": "^3.1.10",
84
+ "express": "^5.0.0",
85
+ "helmet": "^8.1.0",
86
+ "jsonwebtoken": "^9.0.3",
87
+ "morgan": "^1.10.1",
88
+ "multer": "^2.0.2",
89
+ "typescript": "^5.6.0"
90
+ },
91
+ "engines": {
92
+ "node": ">=20"
93
+ }
94
+ }