hono 4.0.3 → 4.0.4

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.
@@ -32,14 +32,21 @@ const html = (strings, ...values) => {
32
32
  const child = children[i2];
33
33
  if (typeof child === "string") {
34
34
  (0, import_html.escapeToBuffer)(child, buffer);
35
+ } else if (typeof child === "number") {
36
+ ;
37
+ buffer[0] += child;
35
38
  } else if (typeof child === "boolean" || child === null || child === void 0) {
36
39
  continue;
37
- } else if (typeof child === "object" && child.isEscaped || typeof child === "number") {
38
- const tmp = child.toString();
39
- if (tmp instanceof Promise) {
40
- buffer.unshift("", tmp);
40
+ } else if (typeof child === "object" && child.isEscaped) {
41
+ if (child.callbacks) {
42
+ buffer.unshift("", child);
41
43
  } else {
42
- buffer[0] += tmp;
44
+ const tmp = child.toString();
45
+ if (tmp instanceof Promise) {
46
+ buffer.unshift("", tmp);
47
+ } else {
48
+ buffer[0] += tmp;
49
+ }
43
50
  }
44
51
  } else if (child instanceof Promise) {
45
52
  buffer.unshift("", child);
@@ -35,6 +35,10 @@ var import_utils2 = require("./utils");
35
35
  const SSG_CONTEXT = "HONO_SSG_CONTEXT";
36
36
  const SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 });
37
37
  const generateFilePath = (routePath, outDir, mimeType) => {
38
+ const hasExtension = /\.[^\/]+$/.test(routePath);
39
+ if (hasExtension) {
40
+ return (0, import_utils2.joinPaths)(outDir, routePath);
41
+ }
38
42
  const extension = determineExtension(mimeType);
39
43
  if (routePath === "/") {
40
44
  return (0, import_utils2.joinPaths)(outDir, `index.${extension}`);
@@ -178,22 +178,24 @@ const applyNode = (node, container) => {
178
178
  applyNodeObject(node, container);
179
179
  }
180
180
  };
181
+ const findChildNodeIndex = (childNodes, child) => {
182
+ if (!child) {
183
+ return;
184
+ }
185
+ for (let i = 0, len = childNodes.length; i < len; i++) {
186
+ if (childNodes[i] === child) {
187
+ return i;
188
+ }
189
+ }
190
+ return;
191
+ };
181
192
  const applyNodeObject = (node, container) => {
182
193
  const next = [];
183
194
  const remove = [];
184
195
  const callbacks = [];
185
196
  getNextChildren(node, container, next, remove, callbacks);
186
- let offset = container.childNodes.length;
187
- const insertBefore = findInsertBefore(node.nN) || next.find((n) => n.e)?.e;
188
- if (insertBefore) {
189
- for (let i = 0; i < offset; i++) {
190
- if (container.childNodes[i] === insertBefore) {
191
- offset = i;
192
- break;
193
- }
194
- }
195
- }
196
197
  const childNodes = container.childNodes;
198
+ let offset = findChildNodeIndex(childNodes, findInsertBefore(node.nN)) ?? findChildNodeIndex(childNodes, next.find((n) => n.e)?.e) ?? childNodes.length;
197
199
  for (let i = 0, len = next.length; i < len; i++, offset++) {
198
200
  const child = next[i];
199
201
  let el;
@@ -237,7 +237,10 @@ const use = (promise) => {
237
237
  }
238
238
  return cachedRes[0];
239
239
  }
240
- promise.then((res2) => resolvedPromiseValueMap.set(promise, [res2])).catch((e) => resolvedPromiseValueMap.set(promise, [void 0, e]));
240
+ promise.then(
241
+ (res2) => resolvedPromiseValueMap.set(promise, [res2]),
242
+ (e) => resolvedPromiseValueMap.set(promise, [void 0, e])
243
+ );
241
244
  const buildData = import_render.buildDataStack.at(-1);
242
245
  if (!buildData) {
243
246
  throw promise;
@@ -245,11 +248,14 @@ const use = (promise) => {
245
248
  const [, node] = buildData;
246
249
  const promiseArray = (_a = node[import_constants.DOM_STASH][1])[STASH_USE] || (_a[STASH_USE] = []);
247
250
  const hookIndex = node[import_constants.DOM_STASH][0]++;
248
- promise.then((res2) => {
249
- promiseArray[hookIndex] = [res2];
250
- }).catch((e) => {
251
- promiseArray[hookIndex] = [void 0, e];
252
- });
251
+ promise.then(
252
+ (res2) => {
253
+ promiseArray[hookIndex] = [res2];
254
+ },
255
+ (e) => {
256
+ promiseArray[hookIndex] = [void 0, e];
257
+ }
258
+ );
253
259
  const res = promiseArray[hookIndex];
254
260
  if (res) {
255
261
  if (res.length === 2) {
@@ -24,7 +24,7 @@ __export(jwt_exports, {
24
24
  verify: () => verify
25
25
  });
26
26
  module.exports = __toCommonJS(jwt_exports);
27
- var import_helper = require("../../helper");
27
+ var import_cookie = require("../../helper/cookie");
28
28
  var import_http_exception = require("../../http-exception");
29
29
  var import_jwt = require("../../utils/jwt");
30
30
  var import_context = require("../../context");
@@ -52,7 +52,7 @@ const jwt = (options) => {
52
52
  token = parts[1];
53
53
  }
54
54
  } else if (options.cookie) {
55
- token = (0, import_helper.getCookie)(ctx)[options.cookie];
55
+ token = (0, import_cookie.getCookie)(ctx)[options.cookie];
56
56
  }
57
57
  if (!token) {
58
58
  throw new import_http_exception.HTTPException(401, {
@@ -34,6 +34,10 @@ const validator = (target, validationFunc) => {
34
34
  const message = `Invalid HTTP header: Content-Type=${contentType}`;
35
35
  throw new import_http_exception.HTTPException(400, { message });
36
36
  }
37
+ if (c.req.bodyCache.json) {
38
+ value = await c.req.bodyCache.json;
39
+ break;
40
+ }
37
41
  try {
38
42
  const arrayBuffer = c.req.bodyCache.arrayBuffer ?? await c.req.raw.arrayBuffer();
39
43
  value = await new Response(arrayBuffer).json();
@@ -45,6 +49,10 @@ const validator = (target, validationFunc) => {
45
49
  }
46
50
  break;
47
51
  case "form": {
52
+ if (c.req.bodyCache.formData) {
53
+ value = c.req.bodyCache.formData;
54
+ break;
55
+ }
48
56
  try {
49
57
  const contentType2 = c.req.header("Content-Type");
50
58
  if (contentType2) {
@@ -9,14 +9,21 @@ var html = (strings, ...values) => {
9
9
  const child = children[i2];
10
10
  if (typeof child === "string") {
11
11
  escapeToBuffer(child, buffer);
12
+ } else if (typeof child === "number") {
13
+ ;
14
+ buffer[0] += child;
12
15
  } else if (typeof child === "boolean" || child === null || child === void 0) {
13
16
  continue;
14
- } else if (typeof child === "object" && child.isEscaped || typeof child === "number") {
15
- const tmp = child.toString();
16
- if (tmp instanceof Promise) {
17
- buffer.unshift("", tmp);
17
+ } else if (typeof child === "object" && child.isEscaped) {
18
+ if (child.callbacks) {
19
+ buffer.unshift("", child);
18
20
  } else {
19
- buffer[0] += tmp;
21
+ const tmp = child.toString();
22
+ if (tmp instanceof Promise) {
23
+ buffer.unshift("", tmp);
24
+ } else {
25
+ buffer[0] += tmp;
26
+ }
20
27
  }
21
28
  } else if (child instanceof Promise) {
22
29
  buffer.unshift("", child);
@@ -6,6 +6,10 @@ import { joinPaths, dirname, filterStaticGenerateRoutes } from "./utils.js";
6
6
  var SSG_CONTEXT = "HONO_SSG_CONTEXT";
7
7
  var SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 });
8
8
  var generateFilePath = (routePath, outDir, mimeType) => {
9
+ const hasExtension = /\.[^\/]+$/.test(routePath);
10
+ if (hasExtension) {
11
+ return joinPaths(outDir, routePath);
12
+ }
9
13
  const extension = determineExtension(mimeType);
10
14
  if (routePath === "/") {
11
15
  return joinPaths(outDir, `index.${extension}`);
@@ -153,22 +153,24 @@ var applyNode = (node, container) => {
153
153
  applyNodeObject(node, container);
154
154
  }
155
155
  };
156
+ var findChildNodeIndex = (childNodes, child) => {
157
+ if (!child) {
158
+ return;
159
+ }
160
+ for (let i = 0, len = childNodes.length; i < len; i++) {
161
+ if (childNodes[i] === child) {
162
+ return i;
163
+ }
164
+ }
165
+ return;
166
+ };
156
167
  var applyNodeObject = (node, container) => {
157
168
  const next = [];
158
169
  const remove = [];
159
170
  const callbacks = [];
160
171
  getNextChildren(node, container, next, remove, callbacks);
161
- let offset = container.childNodes.length;
162
- const insertBefore = findInsertBefore(node.nN) || next.find((n) => n.e)?.e;
163
- if (insertBefore) {
164
- for (let i = 0; i < offset; i++) {
165
- if (container.childNodes[i] === insertBefore) {
166
- offset = i;
167
- break;
168
- }
169
- }
170
- }
171
172
  const childNodes = container.childNodes;
173
+ let offset = findChildNodeIndex(childNodes, findInsertBefore(node.nN)) ?? findChildNodeIndex(childNodes, next.find((n) => n.e)?.e) ?? childNodes.length;
172
174
  for (let i = 0, len = next.length; i < len; i++, offset++) {
173
175
  const child = next[i];
174
176
  let el;
@@ -203,7 +203,10 @@ var use = (promise) => {
203
203
  }
204
204
  return cachedRes[0];
205
205
  }
206
- promise.then((res2) => resolvedPromiseValueMap.set(promise, [res2])).catch((e) => resolvedPromiseValueMap.set(promise, [void 0, e]));
206
+ promise.then(
207
+ (res2) => resolvedPromiseValueMap.set(promise, [res2]),
208
+ (e) => resolvedPromiseValueMap.set(promise, [void 0, e])
209
+ );
207
210
  const buildData = buildDataStack.at(-1);
208
211
  if (!buildData) {
209
212
  throw promise;
@@ -211,11 +214,14 @@ var use = (promise) => {
211
214
  const [, node] = buildData;
212
215
  const promiseArray = (_a = node[DOM_STASH][1])[STASH_USE] || (_a[STASH_USE] = []);
213
216
  const hookIndex = node[DOM_STASH][0]++;
214
- promise.then((res2) => {
215
- promiseArray[hookIndex] = [res2];
216
- }).catch((e) => {
217
- promiseArray[hookIndex] = [void 0, e];
218
- });
217
+ promise.then(
218
+ (res2) => {
219
+ promiseArray[hookIndex] = [res2];
220
+ },
221
+ (e) => {
222
+ promiseArray[hookIndex] = [void 0, e];
223
+ }
224
+ );
219
225
  const res = promiseArray[hookIndex];
220
226
  if (res) {
221
227
  if (res.length === 2) {
@@ -1,5 +1,5 @@
1
1
  // src/middleware/jwt/index.ts
2
- import { getCookie } from "../../helper.js";
2
+ import { getCookie } from "../../helper/cookie/index.js";
3
3
  import { HTTPException } from "../../http-exception.js";
4
4
  import { Jwt } from "../../utils/jwt/index.js";
5
5
  import "../../context.js";
@@ -12,6 +12,10 @@ var validator = (target, validationFunc) => {
12
12
  const message = `Invalid HTTP header: Content-Type=${contentType}`;
13
13
  throw new HTTPException(400, { message });
14
14
  }
15
+ if (c.req.bodyCache.json) {
16
+ value = await c.req.bodyCache.json;
17
+ break;
18
+ }
15
19
  try {
16
20
  const arrayBuffer = c.req.bodyCache.arrayBuffer ?? await c.req.raw.arrayBuffer();
17
21
  value = await new Response(arrayBuffer).json();
@@ -23,6 +27,10 @@ var validator = (target, validationFunc) => {
23
27
  }
24
28
  break;
25
29
  case "form": {
30
+ if (c.req.bodyCache.formData) {
31
+ value = c.req.bodyCache.formData;
32
+ break;
33
+ }
26
34
  try {
27
35
  const contentType2 = c.req.header("Content-Type");
28
36
  if (contentType2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",
@@ -499,7 +499,7 @@
499
499
  "cloudflare",
500
500
  "workers",
501
501
  "fastly",
502
- "compute@edge",
502
+ "compute",
503
503
  "deno",
504
504
  "bun",
505
505
  "lambda",
@@ -1,10 +0,0 @@
1
- export * from './helper/accepts';
2
- export * from './helper/adapter';
3
- export * from './helper/cookie';
4
- export * from './helper/css';
5
- export * from './helper/factory';
6
- export * from './helper/html';
7
- export * from './helper/streaming';
8
- export * from './helper/testing';
9
- export * from './helper/dev';
10
- export * from './adapter/deno/ssg';