hono 4.9.8 → 4.9.9
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.
|
@@ -27,17 +27,17 @@ module.exports = __toCommonJS(route_exports);
|
|
|
27
27
|
var import_constants = require("../../request/constants");
|
|
28
28
|
var import_url = require("../../utils/url");
|
|
29
29
|
const matchedRoutes = (c) => c.req[import_constants.GET_MATCH_RESULT][0].map(([[, route]]) => route);
|
|
30
|
-
const routePath = (c) => matchedRoutes(c)
|
|
31
|
-
const baseRoutePath = (c) => matchedRoutes(c)
|
|
30
|
+
const routePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.path ?? "";
|
|
31
|
+
const baseRoutePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.basePath ?? "";
|
|
32
32
|
const basePathCacheMap = /* @__PURE__ */ new WeakMap();
|
|
33
|
-
const basePath = (c) => {
|
|
34
|
-
|
|
33
|
+
const basePath = (c, index) => {
|
|
34
|
+
index ??= c.req.routeIndex;
|
|
35
35
|
const cache = basePathCacheMap.get(c) || [];
|
|
36
|
-
if (typeof cache[
|
|
37
|
-
return cache[
|
|
36
|
+
if (typeof cache[index] === "string") {
|
|
37
|
+
return cache[index];
|
|
38
38
|
}
|
|
39
39
|
let result;
|
|
40
|
-
const rp = baseRoutePath(c);
|
|
40
|
+
const rp = baseRoutePath(c, index);
|
|
41
41
|
if (!/[:*]/.test(rp)) {
|
|
42
42
|
result = rp;
|
|
43
43
|
} else {
|
|
@@ -56,7 +56,7 @@ const basePath = (c) => {
|
|
|
56
56
|
}
|
|
57
57
|
result = reqPath.substring(0, basePathLength);
|
|
58
58
|
}
|
|
59
|
-
cache[
|
|
59
|
+
cache[index] = result;
|
|
60
60
|
basePathCacheMap.set(c, cache);
|
|
61
61
|
return result;
|
|
62
62
|
};
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
import { GET_MATCH_RESULT } from "../../request/constants.js";
|
|
3
3
|
import { getPattern, splitRoutingPath } from "../../utils/url.js";
|
|
4
4
|
var matchedRoutes = (c) => c.req[GET_MATCH_RESULT][0].map(([[, route]]) => route);
|
|
5
|
-
var routePath = (c) => matchedRoutes(c)
|
|
6
|
-
var baseRoutePath = (c) => matchedRoutes(c)
|
|
5
|
+
var routePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.path ?? "";
|
|
6
|
+
var baseRoutePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.basePath ?? "";
|
|
7
7
|
var basePathCacheMap = /* @__PURE__ */ new WeakMap();
|
|
8
|
-
var basePath = (c) => {
|
|
9
|
-
|
|
8
|
+
var basePath = (c, index) => {
|
|
9
|
+
index ??= c.req.routeIndex;
|
|
10
10
|
const cache = basePathCacheMap.get(c) || [];
|
|
11
|
-
if (typeof cache[
|
|
12
|
-
return cache[
|
|
11
|
+
if (typeof cache[index] === "string") {
|
|
12
|
+
return cache[index];
|
|
13
13
|
}
|
|
14
14
|
let result;
|
|
15
|
-
const rp = baseRoutePath(c);
|
|
15
|
+
const rp = baseRoutePath(c, index);
|
|
16
16
|
if (!/[:*]/.test(rp)) {
|
|
17
17
|
result = rp;
|
|
18
18
|
} else {
|
|
@@ -31,7 +31,7 @@ var basePath = (c) => {
|
|
|
31
31
|
}
|
|
32
32
|
result = reqPath.substring(0, basePathLength);
|
|
33
33
|
}
|
|
34
|
-
cache[
|
|
34
|
+
cache[index] = result;
|
|
35
35
|
basePathCacheMap.set(c, cache);
|
|
36
36
|
return result;
|
|
37
37
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
import type { Hono } from '../../hono';
|
|
6
|
+
import type { Env, Schema } from '../../types';
|
|
6
7
|
import type { FetchEvent } from './types';
|
|
7
8
|
type Handler = (evt: FetchEvent) => void;
|
|
8
9
|
export type HandleOptions = {
|
|
@@ -11,5 +12,5 @@ export type HandleOptions = {
|
|
|
11
12
|
/**
|
|
12
13
|
* Adapter for Service Worker
|
|
13
14
|
*/
|
|
14
|
-
export declare const handle: (app: Hono, opts?: HandleOptions) => Handler;
|
|
15
|
+
export declare const handle: <E extends Env, S extends Schema, BasePath extends string>(app: Hono<E, S, BasePath>, opts?: HandleOptions) => Handler;
|
|
15
16
|
export {};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
import type { Hono } from '../../hono';
|
|
6
|
+
import type { Env, Schema } from '../../types';
|
|
6
7
|
import { handle } from './handler';
|
|
7
8
|
import type { HandleOptions } from './handler';
|
|
8
9
|
/**
|
|
@@ -23,5 +24,5 @@ import type { HandleOptions } from './handler';
|
|
|
23
24
|
* fire(app)
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
|
-
declare const fire: (app: Hono, options?: HandleOptions) => void;
|
|
27
|
+
declare const fire: <E extends Env, S extends Schema, BasePath extends string>(app: Hono<E, S, BasePath>, options?: HandleOptions) => void;
|
|
27
28
|
export { handle, fire };
|
|
@@ -31,22 +31,30 @@ export declare const matchedRoutes: (c: Context) => RouterRoute[];
|
|
|
31
31
|
* Get the route path registered within the handler
|
|
32
32
|
*
|
|
33
33
|
* @param {Context} c - The context object
|
|
34
|
+
* @param {number} index - The index of the root from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching root. Defaults to the current root index.
|
|
34
35
|
* @returns The route path registered within the handler
|
|
35
36
|
*
|
|
36
37
|
* @example
|
|
37
38
|
* ```ts
|
|
38
39
|
* import { routePath } from 'hono/route'
|
|
39
40
|
*
|
|
41
|
+
* app.use('*', (c, next) => {
|
|
42
|
+
* console.log(routePath(c)) // '*'
|
|
43
|
+
* console.log(routePath(c, -1)) // '/posts/:id'
|
|
44
|
+
* return next()
|
|
45
|
+
* })
|
|
46
|
+
*
|
|
40
47
|
* app.get('/posts/:id', (c) => {
|
|
41
48
|
* return c.text(routePath(c)) // '/posts/:id'
|
|
42
49
|
* })
|
|
43
50
|
* ```
|
|
44
51
|
*/
|
|
45
|
-
export declare const routePath: (c: Context) => string;
|
|
52
|
+
export declare const routePath: (c: Context, index?: number) => string;
|
|
46
53
|
/**
|
|
47
54
|
* Get the basePath of the as-is route specified by routing.
|
|
48
55
|
*
|
|
49
56
|
* @param {Context} c - The context object
|
|
57
|
+
* @param {number} index - The index of the root from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching root. Defaults to the current root index.
|
|
50
58
|
* @returns The basePath of the as-is route specified by routing.
|
|
51
59
|
*
|
|
52
60
|
* @example
|
|
@@ -63,5 +71,5 @@ export declare const routePath: (c: Context) => string;
|
|
|
63
71
|
* app.route('/:sub', subApp)
|
|
64
72
|
* ```
|
|
65
73
|
*/
|
|
66
|
-
export declare const baseRoutePath: (c: Context) => string;
|
|
67
|
-
export declare const basePath: (c: Context) => string;
|
|
74
|
+
export declare const baseRoutePath: (c: Context, index?: number) => string;
|
|
75
|
+
export declare const basePath: (c: Context, index?: number) => string;
|