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.
@@ -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
- const dispatchRes = dispatch(i + 1);
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 (!(res instanceof Promise)) {
66
- if (res !== void 0 && "response" in res) {
67
- res = res["response"];
68
- }
69
- if (res && (context.finalized === false || isError)) {
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
  };
@@ -76,6 +76,7 @@ class Context {
76
76
  }
77
77
  };
78
78
  this.status = (status) => {
79
+ this._init = false;
79
80
  this._status = status;
80
81
  };
81
82
  this.set = (key, value) => {
@@ -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 tmp = composed(c);
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
- const dispatchRes = dispatch(i + 1);
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 (!(res instanceof Promise)) {
44
- if (res !== void 0 && "response" in res) {
45
- res = res["response"];
46
- }
47
- if (res && (context.finalized === false || isError)) {
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
@@ -54,6 +54,7 @@ var Context = class {
54
54
  }
55
55
  };
56
56
  this.status = (status) => {
57
+ this._init = false;
57
58
  this._status = status;
58
59
  };
59
60
  this.set = (key, value) => {
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 tmp = composed(c);
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()`"
@@ -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) => C | Promise<C>;
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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "3.10.0",
3
+ "version": "3.10.1",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",