hono 2.6.2 → 3.0.0-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 (89) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/compose.js +6 -0
  3. package/dist/cjs/context.js +32 -6
  4. package/dist/cjs/hono.js +21 -6
  5. package/dist/cjs/middleware/cache/index.js +1 -1
  6. package/dist/cjs/middleware/validator/index.js +29 -2
  7. package/dist/cjs/request.js +94 -36
  8. package/dist/compose.js +6 -0
  9. package/dist/context.js +32 -6
  10. package/dist/hono.js +21 -6
  11. package/dist/middleware/cache/index.js +1 -1
  12. package/dist/middleware/validator/index.js +29 -2
  13. package/dist/request.js +94 -36
  14. package/dist/{compose.d.ts → types/compose.d.ts} +1 -1
  15. package/dist/{context.d.ts → types/context.d.ts} +25 -9
  16. package/dist/types/hono.d.ts +57 -0
  17. package/dist/types/index.d.ts +11 -0
  18. package/dist/{middleware → types/middleware}/basic-auth/index.d.ts +0 -0
  19. package/dist/{middleware → types/middleware}/bearer-auth/index.d.ts +0 -0
  20. package/dist/{middleware → types/middleware}/cache/index.d.ts +0 -0
  21. package/dist/{middleware → types/middleware}/compress/index.d.ts +0 -0
  22. package/dist/{middleware → types/middleware}/cors/index.d.ts +0 -0
  23. package/dist/{middleware → types/middleware}/etag/index.d.ts +0 -0
  24. package/dist/{middleware → types/middleware}/html/index.d.ts +0 -0
  25. package/dist/{middleware → types/middleware}/jsx/index.d.ts +0 -0
  26. package/dist/{middleware → types/middleware}/jsx/jsx-dev-runtime.d.ts +0 -0
  27. package/dist/{middleware → types/middleware}/jsx/jsx-runtime.d.ts +0 -0
  28. package/dist/{middleware → types/middleware}/jwt/index.d.ts +0 -0
  29. package/dist/{middleware → types/middleware}/logger/index.d.ts +0 -0
  30. package/dist/{middleware → types/middleware}/powered-by/index.d.ts +0 -0
  31. package/dist/{middleware → types/middleware}/pretty-json/index.d.ts +0 -0
  32. package/dist/{middleware → types/middleware}/serve-static/bun.d.ts +0 -0
  33. package/dist/{middleware → types/middleware}/serve-static/index.d.ts +0 -0
  34. package/dist/{middleware → types/middleware}/serve-static/module.d.ts +1 -1
  35. package/dist/{middleware → types/middleware}/serve-static/serve-static.d.ts +0 -0
  36. package/dist/types/middleware/validator/index.d.ts +8 -0
  37. package/dist/types/package.json +3 -0
  38. package/dist/types/request.d.ts +44 -0
  39. package/dist/{router → types/router}/reg-exp-router/index.d.ts +0 -0
  40. package/dist/{router → types/router}/reg-exp-router/node.d.ts +0 -0
  41. package/dist/{router → types/router}/reg-exp-router/router.d.ts +0 -0
  42. package/dist/{router → types/router}/reg-exp-router/trie.d.ts +0 -0
  43. package/dist/{router → types/router}/smart-router/index.d.ts +0 -0
  44. package/dist/{router → types/router}/smart-router/router.d.ts +0 -0
  45. package/dist/{router → types/router}/static-router/index.d.ts +0 -0
  46. package/dist/{router → types/router}/static-router/router.d.ts +0 -0
  47. package/dist/{router → types/router}/trie-router/index.d.ts +0 -0
  48. package/dist/{router → types/router}/trie-router/node.d.ts +0 -0
  49. package/dist/{router → types/router}/trie-router/router.d.ts +0 -0
  50. package/dist/{router.d.ts → types/router.d.ts} +0 -0
  51. package/dist/types/types.d.ts +98 -0
  52. package/dist/{utils → types/utils}/body.d.ts +0 -0
  53. package/dist/{utils → types/utils}/buffer.d.ts +0 -0
  54. package/dist/{utils → types/utils}/cloudflare.d.ts +0 -0
  55. package/dist/{utils → types/utils}/cookie.d.ts +0 -0
  56. package/dist/{utils → types/utils}/crypto.d.ts +0 -0
  57. package/dist/{utils → types/utils}/encode.d.ts +0 -0
  58. package/dist/{utils → types/utils}/filepath.d.ts +0 -0
  59. package/dist/{utils → types/utils}/html.d.ts +0 -0
  60. package/dist/{utils → types/utils}/http-status.d.ts +0 -0
  61. package/dist/{utils → types/utils}/json.d.ts +0 -0
  62. package/dist/{utils → types/utils}/jwt/index.d.ts +0 -0
  63. package/dist/{utils → types/utils}/jwt/jwt.d.ts +0 -0
  64. package/dist/{utils → types/utils}/jwt/types.d.ts +0 -0
  65. package/dist/{utils → types/utils}/mime.d.ts +0 -0
  66. package/dist/{utils → types/utils}/object.d.ts +0 -0
  67. package/dist/{utils → types/utils}/types.d.ts +1 -0
  68. package/dist/{utils → types/utils}/url.d.ts +0 -0
  69. package/package.json +57 -54
  70. package/dist/cjs/middleware/validator/middleware.js +0 -137
  71. package/dist/cjs/validator/rule.js +0 -94
  72. package/dist/cjs/validator/sanitizer.js +0 -30
  73. package/dist/cjs/validator/schema.js +0 -16
  74. package/dist/cjs/validator/validator.js +0 -441
  75. package/dist/hono.d.ts +0 -50
  76. package/dist/index.d.ts +0 -13
  77. package/dist/middleware/validator/index.d.ts +0 -2
  78. package/dist/middleware/validator/middleware.d.ts +0 -15
  79. package/dist/middleware/validator/middleware.js +0 -114
  80. package/dist/request.d.ts +0 -39
  81. package/dist/types.d.ts +0 -25
  82. package/dist/validator/rule.d.ts +0 -21
  83. package/dist/validator/rule.js +0 -71
  84. package/dist/validator/sanitizer.d.ts +0 -3
  85. package/dist/validator/sanitizer.js +0 -7
  86. package/dist/validator/schema.d.ts +0 -10
  87. package/dist/validator/schema.js +0 -0
  88. package/dist/validator/validator.d.ts +0 -134
  89. package/dist/validator/validator.js +0 -408
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  <hr />
15
15
 
16
- [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/honojs/hono/ci)](https://github.com/honojs/hono/actions)
16
+ [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/honojs/hono/ci.yml?branch=main)](https://github.com/honojs/hono/actions)
17
17
  [![GitHub](https://img.shields.io/github/license/honojs/hono)](https://github.com/honojs/hono/blob/main/LICENSE)
18
18
  [![npm](https://img.shields.io/npm/v/hono)](https://www.npmjs.com/package/hono)
19
19
  [![npm](https://img.shields.io/npm/dm/hono)](https://www.npmjs.com/package/hono)
@@ -57,7 +57,13 @@ const compose = (middleware, onNotFound, onError) => {
57
57
  }
58
58
  }
59
59
  }
60
+ if (res instanceof Response && "response" in res) {
61
+ res = res["response"];
62
+ }
60
63
  if (!(res instanceof Promise)) {
64
+ if (res !== void 0 && "response" in res) {
65
+ res = res["response"];
66
+ }
61
67
  if (res && (context.finalized === false || isError)) {
62
68
  context.res = res;
63
69
  }
@@ -21,18 +21,34 @@ __export(context_exports, {
21
21
  Context: () => Context
22
22
  });
23
23
  module.exports = __toCommonJS(context_exports);
24
+ var import_request = require("./request");
24
25
  var import_cookie = require("./utils/cookie");
25
26
  class Context {
26
- constructor(req, env = {}, executionCtx = void 0, notFoundHandler = () => new Response()) {
27
+ constructor(req, options) {
28
+ this.env = {};
29
+ this.finalized = false;
27
30
  this.error = void 0;
28
31
  this._status = 200;
29
32
  this._pretty = false;
30
33
  this._prettySpace = 2;
31
- this._executionCtx = executionCtx;
32
- this.req = req;
33
- this.env = env;
34
- this.notFoundHandler = notFoundHandler;
35
- this.finalized = false;
34
+ this.notFoundHandler = () => new Response();
35
+ this.rawRequest = req;
36
+ if (options) {
37
+ this._executionCtx = options.executionCtx;
38
+ this._paramData = options.paramData;
39
+ this.env = options.env;
40
+ if (options.notFoundHandler) {
41
+ this.notFoundHandler = options.notFoundHandler;
42
+ }
43
+ }
44
+ }
45
+ get req() {
46
+ if (this._req) {
47
+ return this._req;
48
+ } else {
49
+ this._req = new import_request.HonoRequest(this.rawRequest, this._paramData);
50
+ return this._req;
51
+ }
36
52
  }
37
53
  get event() {
38
54
  if (this._executionCtx instanceof FetchEvent) {
@@ -145,6 +161,13 @@ class Context {
145
161
  headers["content-type"] = "application/json; charset=UTF-8";
146
162
  return this.newResponse(body, status, headers);
147
163
  }
164
+ jsonT(object, status = this._status, headers = {}) {
165
+ return {
166
+ response: this.json(object, status, headers),
167
+ data: object,
168
+ format: "json"
169
+ };
170
+ }
148
171
  html(html, status = this._status, headers = {}) {
149
172
  headers["content-type"] = "text/html; charset=UTF-8";
150
173
  return this.newResponse(html, status, headers);
@@ -181,6 +204,9 @@ class Context {
181
204
  if (global?.process?.release?.name === "node") {
182
205
  return "node";
183
206
  }
207
+ if (global?.__lagon__ !== void 0) {
208
+ return "lagon";
209
+ }
184
210
  return "other";
185
211
  }
186
212
  }
package/dist/cjs/hono.js CHANGED
@@ -23,7 +23,6 @@ __export(hono_exports, {
23
23
  module.exports = __toCommonJS(hono_exports);
24
24
  var import_compose = require("./compose");
25
25
  var import_context = require("./context");
26
- var import_request = require("./request");
27
26
  var import_router = require("./router");
28
27
  var import_reg_exp_router = require("./router/reg-exp-router");
29
28
  var import_smart_router = require("./router/smart-router");
@@ -52,6 +51,10 @@ class Hono extends defineDynamicClass() {
52
51
  const message = "Internal Server Error";
53
52
  return c.text(message, 500);
54
53
  };
54
+ this.build = () => {
55
+ const app = {};
56
+ return {};
57
+ };
55
58
  this.handleEvent = (event) => {
56
59
  return this.dispatch(event.request, event);
57
60
  };
@@ -62,7 +65,6 @@ class Hono extends defineDynamicClass() {
62
65
  const req = input instanceof Request ? input : new Request(input, requestInit);
63
66
  return await this.fetch(req);
64
67
  };
65
- (0, import_request.extendRequestPrototype)();
66
68
  const allMethods = [...import_router.METHODS, import_router.METHOD_NAME_ALL_LOWERCASE];
67
69
  allMethods.map((method) => {
68
70
  this[method] = (args1, ...args) => {
@@ -149,25 +151,38 @@ class Hono extends defineDynamicClass() {
149
151
  const path = (0, import_url.getPathFromURL)(request.url, this.strict);
150
152
  const method = request.method;
151
153
  const result = this.matchRoute(method, path);
152
- request.paramData = result?.params;
153
- const c = new import_context.Context(request, env, eventOrExecutionCtx, this.notFoundHandler);
154
+ const paramData = result?.params;
155
+ const c = new import_context.Context(request, {
156
+ env,
157
+ executionCtx: eventOrExecutionCtx,
158
+ notFoundHandler: this.notFoundHandler,
159
+ paramData
160
+ });
154
161
  if (result && result.handlers.length === 1) {
155
162
  const handler = result.handlers[0];
156
163
  let res;
157
164
  try {
158
165
  res = handler(c, async () => {
159
166
  });
160
- if (!res)
167
+ if (!res) {
161
168
  return this.notFoundHandler(c);
169
+ }
162
170
  } catch (err) {
163
171
  return this.handleError(err, c);
164
172
  }
165
- if (res instanceof Response)
173
+ if ("response" in res) {
174
+ res = res.response;
175
+ }
176
+ if (res instanceof Response) {
166
177
  return res;
178
+ }
167
179
  return (async () => {
168
180
  let awaited;
169
181
  try {
170
182
  awaited = await res;
183
+ if (awaited !== void 0 && "response" in awaited) {
184
+ awaited = awaited["response"];
185
+ }
171
186
  if (!awaited) {
172
187
  return this.notFoundHandler(c);
173
188
  }
@@ -30,7 +30,7 @@ const cache = (options) => {
30
30
  response.headers.append("Cache-Control", options.cacheControl);
31
31
  };
32
32
  return async (c, next) => {
33
- const key = c.req;
33
+ const key = c.req.raw;
34
34
  const cache2 = await caches.open(options.cacheName);
35
35
  const response = await cache2.match(key);
36
36
  if (!response) {
@@ -18,10 +18,37 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var validator_exports = {};
20
20
  __export(validator_exports, {
21
- validator: () => import_middleware.validatorMiddleware
21
+ validator: () => validator
22
22
  });
23
23
  module.exports = __toCommonJS(validator_exports);
24
- var import_middleware = require("./middleware");
24
+ var import_object = require("../../utils/object");
25
+ const validator = (type, validationFunc) => {
26
+ return async (c, next) => {
27
+ let value = {};
28
+ switch (type) {
29
+ case "json":
30
+ value = await c.req.json();
31
+ break;
32
+ case "form":
33
+ value = await c.req.parseBody();
34
+ break;
35
+ case "query":
36
+ value = c.req.query();
37
+ break;
38
+ case "queries":
39
+ value = c.req.queries();
40
+ break;
41
+ }
42
+ const res = validationFunc(value, c);
43
+ if (res instanceof Response || res instanceof Promise) {
44
+ return res;
45
+ }
46
+ const target = c.req.valid();
47
+ const newObject = (0, import_object.mergeObjects)(target, res);
48
+ c.req.valid(newObject);
49
+ await next();
50
+ };
51
+ };
25
52
  // Annotate the CommonJS export names for ESM import in node:
26
53
  0 && (module.exports = {
27
54
  validator
@@ -18,17 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var request_exports = {};
20
20
  __export(request_exports, {
21
- extendRequestPrototype: () => extendRequestPrototype
21
+ HonoRequest: () => HonoRequest
22
22
  });
23
23
  module.exports = __toCommonJS(request_exports);
24
24
  var import_body = require("./utils/body");
25
25
  var import_cookie = require("./utils/cookie");
26
26
  var import_url = require("./utils/url");
27
- function extendRequestPrototype() {
28
- if (!!Request.prototype.param) {
29
- return;
27
+ class HonoRequest {
28
+ constructor(request, paramData) {
29
+ this.raw = request;
30
+ this.paramData = paramData;
31
+ this.data = {};
30
32
  }
31
- Request.prototype.param = function(key) {
33
+ param(key) {
32
34
  if (this.paramData) {
33
35
  if (key) {
34
36
  const param = this.paramData[key];
@@ -36,7 +38,7 @@ function extendRequestPrototype() {
36
38
  } else {
37
39
  const decoded = {};
38
40
  for (const [key2, value] of Object.entries(this.paramData)) {
39
- if (value) {
41
+ if (value && typeof value === "string") {
40
42
  decoded[key2] = decodeURIComponent(value);
41
43
  }
42
44
  }
@@ -44,21 +46,8 @@ function extendRequestPrototype() {
44
46
  }
45
47
  }
46
48
  return null;
47
- };
48
- Request.prototype.header = function(name) {
49
- if (!this.headerData) {
50
- this.headerData = {};
51
- this.headers.forEach((value, key) => {
52
- this.headerData[key] = value;
53
- });
54
- }
55
- if (name) {
56
- return this.headerData[name.toLowerCase()];
57
- } else {
58
- return this.headerData;
59
- }
60
- };
61
- Request.prototype.query = function(key) {
49
+ }
50
+ query(key) {
62
51
  const queryString = (0, import_url.getQueryStringFromURL)(this.url);
63
52
  const searchParams = new URLSearchParams(queryString);
64
53
  if (!this.queryData) {
@@ -72,8 +61,8 @@ function extendRequestPrototype() {
72
61
  } else {
73
62
  return this.queryData;
74
63
  }
75
- };
76
- Request.prototype.queries = function(key) {
64
+ }
65
+ queries(key) {
77
66
  const queryString = (0, import_url.getQueryStringFromURL)(this.url);
78
67
  const searchParams = new URLSearchParams(queryString);
79
68
  if (key) {
@@ -85,9 +74,24 @@ function extendRequestPrototype() {
85
74
  }
86
75
  return result;
87
76
  }
88
- };
89
- Request.prototype.cookie = function(key) {
90
- const cookie = this.headers.get("Cookie") || "";
77
+ }
78
+ header(name) {
79
+ if (!this.headerData) {
80
+ this.headerData = {};
81
+ this.raw.headers.forEach((value, key) => {
82
+ this.headerData[key] = value;
83
+ });
84
+ }
85
+ if (name) {
86
+ return this.headerData[name.toLowerCase()];
87
+ } else {
88
+ return this.headerData;
89
+ }
90
+ }
91
+ cookie(key) {
92
+ const cookie = this.raw.headers.get("Cookie");
93
+ if (!cookie)
94
+ return;
91
95
  const obj = (0, import_cookie.parse)(cookie);
92
96
  if (key) {
93
97
  const value = obj[key];
@@ -95,28 +99,40 @@ function extendRequestPrototype() {
95
99
  } else {
96
100
  return obj;
97
101
  }
98
- };
99
- Request.prototype.parseBody = async function() {
102
+ }
103
+ async parseBody() {
100
104
  let body;
101
105
  if (!this.bodyData) {
102
- body = await (0, import_body.parseBody)(this);
106
+ body = await (0, import_body.parseBody)(this.raw);
103
107
  this.bodyData = body;
104
108
  } else {
105
109
  body = this.bodyData;
106
110
  }
107
111
  return body;
108
- };
109
- Request.prototype.json = async function() {
112
+ }
113
+ async json() {
110
114
  let jsonData;
111
115
  if (!this.jsonData) {
112
- jsonData = JSON.parse(await this.text());
116
+ jsonData = this.raw.json();
113
117
  this.jsonData = jsonData;
114
118
  } else {
115
119
  jsonData = this.jsonData;
116
120
  }
117
121
  return jsonData;
118
- };
119
- Request.prototype.valid = function(data) {
122
+ }
123
+ async text() {
124
+ return this.raw.text();
125
+ }
126
+ async arrayBuffer() {
127
+ return this.raw.arrayBuffer();
128
+ }
129
+ async blob() {
130
+ return this.raw.blob();
131
+ }
132
+ async formData() {
133
+ return this.raw.formData();
134
+ }
135
+ valid(data) {
120
136
  if (!this.data) {
121
137
  this.data = {};
122
138
  }
@@ -124,9 +140,51 @@ function extendRequestPrototype() {
124
140
  this.data = data;
125
141
  }
126
142
  return this.data;
127
- };
143
+ }
144
+ get url() {
145
+ return this.raw.url;
146
+ }
147
+ get method() {
148
+ return this.raw.method;
149
+ }
150
+ get headers() {
151
+ return this.raw.headers;
152
+ }
153
+ get redirect() {
154
+ return this.raw.redirect;
155
+ }
156
+ get body() {
157
+ return this.raw.body;
158
+ }
159
+ get bodyUsed() {
160
+ return this.raw.bodyUsed;
161
+ }
162
+ get cache() {
163
+ return this.raw.cache;
164
+ }
165
+ get credentials() {
166
+ return this.raw.credentials;
167
+ }
168
+ get integrity() {
169
+ return this.raw.integrity;
170
+ }
171
+ get keepalive() {
172
+ return this.raw.keepalive;
173
+ }
174
+ get mode() {
175
+ return this.raw.mode;
176
+ }
177
+ get referrer() {
178
+ return this.raw.referrer;
179
+ }
180
+ get refererPolicy() {
181
+ return this.raw.referrerPolicy;
182
+ }
183
+ get signal() {
184
+ return this.raw.signal;
185
+ }
128
186
  }
129
187
  // Annotate the CommonJS export names for ESM import in node:
130
188
  0 && (module.exports = {
131
- extendRequestPrototype
189
+ HonoRequest
132
190
  });
package/dist/compose.js CHANGED
@@ -35,7 +35,13 @@ var compose = (middleware, onNotFound, onError) => {
35
35
  }
36
36
  }
37
37
  }
38
+ if (res instanceof Response && "response" in res) {
39
+ res = res["response"];
40
+ }
38
41
  if (!(res instanceof Promise)) {
42
+ if (res !== void 0 && "response" in res) {
43
+ res = res["response"];
44
+ }
39
45
  if (res && (context.finalized === false || isError)) {
40
46
  context.res = res;
41
47
  }
package/dist/context.js CHANGED
@@ -1,16 +1,32 @@
1
1
  // src/context.ts
2
+ import { HonoRequest } from "./request.js";
2
3
  import { serialize } from "./utils/cookie.js";
3
4
  var Context = class {
4
- constructor(req, env = {}, executionCtx = void 0, notFoundHandler = () => new Response()) {
5
+ constructor(req, options) {
6
+ this.env = {};
7
+ this.finalized = false;
5
8
  this.error = void 0;
6
9
  this._status = 200;
7
10
  this._pretty = false;
8
11
  this._prettySpace = 2;
9
- this._executionCtx = executionCtx;
10
- this.req = req;
11
- this.env = env;
12
- this.notFoundHandler = notFoundHandler;
13
- this.finalized = false;
12
+ this.notFoundHandler = () => new Response();
13
+ this.rawRequest = req;
14
+ if (options) {
15
+ this._executionCtx = options.executionCtx;
16
+ this._paramData = options.paramData;
17
+ this.env = options.env;
18
+ if (options.notFoundHandler) {
19
+ this.notFoundHandler = options.notFoundHandler;
20
+ }
21
+ }
22
+ }
23
+ get req() {
24
+ if (this._req) {
25
+ return this._req;
26
+ } else {
27
+ this._req = new HonoRequest(this.rawRequest, this._paramData);
28
+ return this._req;
29
+ }
14
30
  }
15
31
  get event() {
16
32
  if (this._executionCtx instanceof FetchEvent) {
@@ -123,6 +139,13 @@ var Context = class {
123
139
  headers["content-type"] = "application/json; charset=UTF-8";
124
140
  return this.newResponse(body, status, headers);
125
141
  }
142
+ jsonT(object, status = this._status, headers = {}) {
143
+ return {
144
+ response: this.json(object, status, headers),
145
+ data: object,
146
+ format: "json"
147
+ };
148
+ }
126
149
  html(html, status = this._status, headers = {}) {
127
150
  headers["content-type"] = "text/html; charset=UTF-8";
128
151
  return this.newResponse(html, status, headers);
@@ -159,6 +182,9 @@ var Context = class {
159
182
  if (global?.process?.release?.name === "node") {
160
183
  return "node";
161
184
  }
185
+ if (global?.__lagon__ !== void 0) {
186
+ return "lagon";
187
+ }
162
188
  return "other";
163
189
  }
164
190
  };
package/dist/hono.js CHANGED
@@ -1,7 +1,6 @@
1
1
  // src/hono.ts
2
2
  import { compose } from "./compose.js";
3
3
  import { Context } from "./context.js";
4
- import { extendRequestPrototype } from "./request.js";
5
4
  import { METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE, METHODS } from "./router.js";
6
5
  import { RegExpRouter } from "./router/reg-exp-router/index.js";
7
6
  import { SmartRouter } from "./router/smart-router/index.js";
@@ -30,6 +29,10 @@ var Hono = class extends defineDynamicClass() {
30
29
  const message = "Internal Server Error";
31
30
  return c.text(message, 500);
32
31
  };
32
+ this.build = () => {
33
+ const app = {};
34
+ return {};
35
+ };
33
36
  this.handleEvent = (event) => {
34
37
  return this.dispatch(event.request, event);
35
38
  };
@@ -40,7 +43,6 @@ var Hono = class extends defineDynamicClass() {
40
43
  const req = input instanceof Request ? input : new Request(input, requestInit);
41
44
  return await this.fetch(req);
42
45
  };
43
- extendRequestPrototype();
44
46
  const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
45
47
  allMethods.map((method) => {
46
48
  this[method] = (args1, ...args) => {
@@ -127,25 +129,38 @@ var Hono = class extends defineDynamicClass() {
127
129
  const path = getPathFromURL(request.url, this.strict);
128
130
  const method = request.method;
129
131
  const result = this.matchRoute(method, path);
130
- request.paramData = result?.params;
131
- const c = new Context(request, env, eventOrExecutionCtx, this.notFoundHandler);
132
+ const paramData = result?.params;
133
+ const c = new Context(request, {
134
+ env,
135
+ executionCtx: eventOrExecutionCtx,
136
+ notFoundHandler: this.notFoundHandler,
137
+ paramData
138
+ });
132
139
  if (result && result.handlers.length === 1) {
133
140
  const handler = result.handlers[0];
134
141
  let res;
135
142
  try {
136
143
  res = handler(c, async () => {
137
144
  });
138
- if (!res)
145
+ if (!res) {
139
146
  return this.notFoundHandler(c);
147
+ }
140
148
  } catch (err) {
141
149
  return this.handleError(err, c);
142
150
  }
143
- if (res instanceof Response)
151
+ if ("response" in res) {
152
+ res = res.response;
153
+ }
154
+ if (res instanceof Response) {
144
155
  return res;
156
+ }
145
157
  return (async () => {
146
158
  let awaited;
147
159
  try {
148
160
  awaited = await res;
161
+ if (awaited !== void 0 && "response" in awaited) {
162
+ awaited = awaited["response"];
163
+ }
149
164
  if (!awaited) {
150
165
  return this.notFoundHandler(c);
151
166
  }
@@ -8,7 +8,7 @@ var cache = (options) => {
8
8
  response.headers.append("Cache-Control", options.cacheControl);
9
9
  };
10
10
  return async (c, next) => {
11
- const key = c.req;
11
+ const key = c.req.raw;
12
12
  const cache2 = await caches.open(options.cacheName);
13
13
  const response = await cache2.match(key);
14
14
  if (!response) {
@@ -1,5 +1,32 @@
1
1
  // src/middleware/validator/index.ts
2
- import { validatorMiddleware } from "./middleware.js";
2
+ import { mergeObjects } from "../../utils/object.js";
3
+ var validator = (type, validationFunc) => {
4
+ return async (c, next) => {
5
+ let value = {};
6
+ switch (type) {
7
+ case "json":
8
+ value = await c.req.json();
9
+ break;
10
+ case "form":
11
+ value = await c.req.parseBody();
12
+ break;
13
+ case "query":
14
+ value = c.req.query();
15
+ break;
16
+ case "queries":
17
+ value = c.req.queries();
18
+ break;
19
+ }
20
+ const res = validationFunc(value, c);
21
+ if (res instanceof Response || res instanceof Promise) {
22
+ return res;
23
+ }
24
+ const target = c.req.valid();
25
+ const newObject = mergeObjects(target, res);
26
+ c.req.valid(newObject);
27
+ await next();
28
+ };
29
+ };
3
30
  export {
4
- validatorMiddleware as validator
31
+ validator
5
32
  };