hono 3.10.0 → 3.10.1
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/dist/cjs/compose.js +9 -29
- package/dist/cjs/context.js +1 -0
- package/dist/cjs/hono-base.js +1 -2
- package/dist/compose.js +9 -29
- package/dist/context.js +1 -0
- package/dist/hono-base.js +1 -2
- package/dist/types/compose.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/compose.js
CHANGED
|
@@ -26,7 +26,7 @@ const compose = (middleware, onError, onNotFound) => {
|
|
|
26
26
|
return (context, next) => {
|
|
27
27
|
let index = -1;
|
|
28
28
|
return dispatch(0);
|
|
29
|
-
function dispatch(i) {
|
|
29
|
+
async function dispatch(i) {
|
|
30
30
|
if (i <= index) {
|
|
31
31
|
throw new Error("next() called multiple times");
|
|
32
32
|
}
|
|
@@ -48,9 +48,8 @@ const compose = (middleware, onError, onNotFound) => {
|
|
|
48
48
|
}
|
|
49
49
|
} else {
|
|
50
50
|
try {
|
|
51
|
-
res = handler(context, () => {
|
|
52
|
-
|
|
53
|
-
return dispatchRes instanceof Promise ? dispatchRes : Promise.resolve(dispatchRes);
|
|
51
|
+
res = await handler(context, () => {
|
|
52
|
+
return dispatch(i + 1);
|
|
54
53
|
});
|
|
55
54
|
} catch (err) {
|
|
56
55
|
if (err instanceof Error && context instanceof import_context.Context && onError) {
|
|
@@ -62,32 +61,13 @@ const compose = (middleware, onError, onNotFound) => {
|
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
context.res = res;
|
|
71
|
-
}
|
|
72
|
-
return context;
|
|
73
|
-
} else {
|
|
74
|
-
return res.then((res2) => {
|
|
75
|
-
if (res2 !== void 0 && "response" in res2) {
|
|
76
|
-
res2 = res2["response"];
|
|
77
|
-
}
|
|
78
|
-
if (res2 && context.finalized === false) {
|
|
79
|
-
context.res = res2;
|
|
80
|
-
}
|
|
81
|
-
return context;
|
|
82
|
-
}).catch(async (err) => {
|
|
83
|
-
if (err instanceof Error && context instanceof import_context.Context && onError) {
|
|
84
|
-
context.error = err;
|
|
85
|
-
context.res = await onError(err, context);
|
|
86
|
-
return context;
|
|
87
|
-
}
|
|
88
|
-
throw err;
|
|
89
|
-
});
|
|
64
|
+
if (res !== void 0 && "response" in res) {
|
|
65
|
+
res = res["response"];
|
|
66
|
+
}
|
|
67
|
+
if (res && (context.finalized === false || isError)) {
|
|
68
|
+
context.res = res;
|
|
90
69
|
}
|
|
70
|
+
return context;
|
|
91
71
|
}
|
|
92
72
|
};
|
|
93
73
|
};
|
package/dist/cjs/context.js
CHANGED
package/dist/cjs/hono-base.js
CHANGED
|
@@ -255,8 +255,7 @@ class Hono extends defineDynamicClass() {
|
|
|
255
255
|
const composed = (0, import_compose.compose)(handlers, this.errorHandler, this.notFoundHandler);
|
|
256
256
|
return (async () => {
|
|
257
257
|
try {
|
|
258
|
-
const
|
|
259
|
-
const context = tmp.constructor.name === "Promise" ? await tmp : tmp;
|
|
258
|
+
const context = await composed(c);
|
|
260
259
|
if (!context.finalized) {
|
|
261
260
|
throw new Error(
|
|
262
261
|
"Context is not finalized. You may forget returning Response object or `await next()`"
|
package/dist/compose.js
CHANGED
|
@@ -4,7 +4,7 @@ var compose = (middleware, onError, onNotFound) => {
|
|
|
4
4
|
return (context, next) => {
|
|
5
5
|
let index = -1;
|
|
6
6
|
return dispatch(0);
|
|
7
|
-
function dispatch(i) {
|
|
7
|
+
async function dispatch(i) {
|
|
8
8
|
if (i <= index) {
|
|
9
9
|
throw new Error("next() called multiple times");
|
|
10
10
|
}
|
|
@@ -26,9 +26,8 @@ var compose = (middleware, onError, onNotFound) => {
|
|
|
26
26
|
}
|
|
27
27
|
} else {
|
|
28
28
|
try {
|
|
29
|
-
res = handler(context, () => {
|
|
30
|
-
|
|
31
|
-
return dispatchRes instanceof Promise ? dispatchRes : Promise.resolve(dispatchRes);
|
|
29
|
+
res = await handler(context, () => {
|
|
30
|
+
return dispatch(i + 1);
|
|
32
31
|
});
|
|
33
32
|
} catch (err) {
|
|
34
33
|
if (err instanceof Error && context instanceof Context && onError) {
|
|
@@ -40,32 +39,13 @@ var compose = (middleware, onError, onNotFound) => {
|
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
context.res = res;
|
|
49
|
-
}
|
|
50
|
-
return context;
|
|
51
|
-
} else {
|
|
52
|
-
return res.then((res2) => {
|
|
53
|
-
if (res2 !== void 0 && "response" in res2) {
|
|
54
|
-
res2 = res2["response"];
|
|
55
|
-
}
|
|
56
|
-
if (res2 && context.finalized === false) {
|
|
57
|
-
context.res = res2;
|
|
58
|
-
}
|
|
59
|
-
return context;
|
|
60
|
-
}).catch(async (err) => {
|
|
61
|
-
if (err instanceof Error && context instanceof Context && onError) {
|
|
62
|
-
context.error = err;
|
|
63
|
-
context.res = await onError(err, context);
|
|
64
|
-
return context;
|
|
65
|
-
}
|
|
66
|
-
throw err;
|
|
67
|
-
});
|
|
42
|
+
if (res !== void 0 && "response" in res) {
|
|
43
|
+
res = res["response"];
|
|
44
|
+
}
|
|
45
|
+
if (res && (context.finalized === false || isError)) {
|
|
46
|
+
context.res = res;
|
|
68
47
|
}
|
|
48
|
+
return context;
|
|
69
49
|
}
|
|
70
50
|
};
|
|
71
51
|
};
|
package/dist/context.js
CHANGED
package/dist/hono-base.js
CHANGED
|
@@ -233,8 +233,7 @@ var Hono = class extends defineDynamicClass() {
|
|
|
233
233
|
const composed = compose(handlers, this.errorHandler, this.notFoundHandler);
|
|
234
234
|
return (async () => {
|
|
235
235
|
try {
|
|
236
|
-
const
|
|
237
|
-
const context = tmp.constructor.name === "Promise" ? await tmp : tmp;
|
|
236
|
+
const context = await composed(c);
|
|
238
237
|
if (!context.finalized) {
|
|
239
238
|
throw new Error(
|
|
240
239
|
"Context is not finalized. You may forget returning Response object or `await next()`"
|
package/dist/types/compose.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ interface ComposeContext {
|
|
|
4
4
|
finalized: boolean;
|
|
5
5
|
res: unknown;
|
|
6
6
|
}
|
|
7
|
-
export declare const compose: <C extends ComposeContext, E extends Env = Env>(middleware: [Function, ParamIndexMap | Params][], onError?: ErrorHandler<E> | undefined, onNotFound?: NotFoundHandler<E> | undefined) => (context: C, next?: Function) =>
|
|
7
|
+
export declare const compose: <C extends ComposeContext, E extends Env = Env>(middleware: [Function, ParamIndexMap | Params][], onError?: ErrorHandler<E> | undefined, onNotFound?: NotFoundHandler<E> | undefined) => (context: C, next?: Function) => Promise<C>;
|
|
8
8
|
export {};
|