express-fastify-runtime 0.1.1 → 0.1.3
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/changelog/log-2026-06-25.md +38 -0
- package/changelog/log-2026-06-26.md +54 -0
- package/dist/app/compile.d.ts +6 -0
- package/dist/app/compile.d.ts.map +1 -1
- package/dist/app/compile.js +51 -17
- package/dist/app/compile.js.map +1 -1
- package/dist/app/flattenRouter.d.ts +17 -1
- package/dist/app/flattenRouter.d.ts.map +1 -1
- package/dist/app/flattenRouter.js +41 -3
- package/dist/app/flattenRouter.js.map +1 -1
- package/dist/app/introspectExpress.d.ts +6 -0
- package/dist/app/introspectExpress.d.ts.map +1 -1
- package/dist/app/introspectExpress.js +13 -0
- package/dist/app/introspectExpress.js.map +1 -1
- package/dist/fastify/adapters/define.d.ts +24 -0
- package/dist/fastify/adapters/define.d.ts.map +1 -0
- package/dist/fastify/adapters/define.js +52 -0
- package/dist/fastify/adapters/define.js.map +1 -0
- package/dist/fastify/adapters/request.d.ts.map +1 -1
- package/dist/fastify/adapters/request.js +24 -44
- package/dist/fastify/adapters/request.js.map +1 -1
- package/dist/fastify/adapters/response.js +4 -4
- package/dist/fastify/adapters/response.js.map +1 -1
- package/dist/fastify/register.d.ts +13 -0
- package/dist/fastify/register.d.ts.map +1 -1
- package/dist/fastify/register.js +28 -0
- package/dist/fastify/register.js.map +1 -1
- package/dist/runtime/fast.d.ts.map +1 -1
- package/dist/runtime/fast.js +9 -3
- package/dist/runtime/fast.js.map +1 -1
- package/dist/runtime/lifecycle.d.ts.map +1 -1
- package/dist/runtime/lifecycle.js +3 -0
- package/dist/runtime/lifecycle.js.map +1 -1
- package/dist/runtime/routingOptions.d.ts +16 -0
- package/dist/runtime/routingOptions.d.ts.map +1 -0
- package/dist/runtime/routingOptions.js +31 -0
- package/dist/runtime/routingOptions.js.map +1 -0
- package/dist/utils/detect.d.ts.map +1 -1
- package/dist/utils/detect.js +5 -0
- package/dist/utils/detect.js.map +1 -1
- package/dist/utils/expressPath.d.ts +24 -0
- package/dist/utils/expressPath.d.ts.map +1 -0
- package/dist/utils/expressPath.js +47 -0
- package/dist/utils/expressPath.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Translate an Express route path string into a Fastify (find-my-way) path.
|
|
4
|
+
*
|
|
5
|
+
* Express and Fastify share `/:param` and `/static`, but wildcards differ:
|
|
6
|
+
* - Express 4: bare `*` → the match is exposed as `req.params[0]` (then `[1]`, ...).
|
|
7
|
+
* - Express 5: named `*splat` → exposed as `req.params.splat`.
|
|
8
|
+
* - Fastify/find-my-way: a single trailing `*`, exposed as `req.params['*']`.
|
|
9
|
+
* Passing an Express path verbatim to Fastify therefore (a) crashes at registration for Express 5's
|
|
10
|
+
* `*splat` ("Wildcard must be the last character"), and (b) loses the wildcard value (handlers read
|
|
11
|
+
* `params[0]`/`params.splat`, Fastify wrote `params['*']`).
|
|
12
|
+
*
|
|
13
|
+
* `toFastifyPath` rewrites a trailing wildcard to Fastify's `*` and reports the Express key to bridge
|
|
14
|
+
* back at request time. Anything we can't translate safely (mid-path or multiple wildcards) returns
|
|
15
|
+
* null so the caller leaves that route on the Express lane. Plain param/static paths are returned
|
|
16
|
+
* unchanged with `wildcard: null` (zero behavior change for the common case).
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.toFastifyPath = toFastifyPath;
|
|
20
|
+
const STAR = '*';
|
|
21
|
+
function toFastifyPath(expressPath) {
|
|
22
|
+
if (typeof expressPath !== 'string' || expressPath.length === 0)
|
|
23
|
+
return null;
|
|
24
|
+
// No wildcard → identical syntax on both routers (params, statics). Return as-is.
|
|
25
|
+
if (!expressPath.includes(STAR))
|
|
26
|
+
return { url: expressPath, wildcard: null };
|
|
27
|
+
// Count wildcard occurrences. Fastify supports exactly one, and only as the final segment.
|
|
28
|
+
const starCount = (expressPath.match(/\*/g) ?? []).length;
|
|
29
|
+
if (starCount !== 1)
|
|
30
|
+
return null; // multiple wildcards → Express lane
|
|
31
|
+
const starIndex = expressPath.indexOf(STAR);
|
|
32
|
+
// Express 5 names the wildcard: `*name` (chars right after `*`). Express 4 uses a bare `*`.
|
|
33
|
+
const after = expressPath.slice(starIndex + 1);
|
|
34
|
+
const nameMatch = after.match(/^([A-Za-z_$][\w$]*)/);
|
|
35
|
+
const wildcardName = nameMatch ? nameMatch[1] : null;
|
|
36
|
+
const trailingAfterName = nameMatch ? after.slice(nameMatch[1].length) : after;
|
|
37
|
+
// The wildcard must be last (only an optional trailing slash may follow). Otherwise we can't map
|
|
38
|
+
// it to Fastify's trailing `*`.
|
|
39
|
+
if (trailingAfterName !== '' && trailingAfterName !== '/')
|
|
40
|
+
return null;
|
|
41
|
+
const before = expressPath.slice(0, starIndex); // includes the slash before `*`
|
|
42
|
+
const url = before + STAR;
|
|
43
|
+
// Express 4 exposes a bare `*` as the numeric key '0'; Express 5 uses the given name.
|
|
44
|
+
const wildcard = wildcardName ?? '0';
|
|
45
|
+
return { url, wildcard };
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=expressPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expressPath.js","sourceRoot":"","sources":["../../src/utils/expressPath.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AAWH,sCA0BC;AA5BD,MAAM,IAAI,GAAG,GAAG,CAAC;AAEjB,SAAgB,aAAa,CAAC,WAAmB;IAC/C,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAE7E,kFAAkF;IAClF,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAE7E,2FAA2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