hono 4.6.13 → 4.6.15

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.
@@ -240,12 +240,15 @@ class Context {
240
240
  this.#preparedHeaders = {};
241
241
  }
242
242
  this.#preparedHeaders["content-type"] = TEXT_PLAIN;
243
- return typeof arg === "number" ? this.#newResponse(text, arg, headers) : this.#newResponse(text, arg);
243
+ if (typeof arg === "number") {
244
+ return this.#newResponse(text, arg, headers);
245
+ }
246
+ return this.#newResponse(text, arg);
244
247
  };
245
248
  json = (object, arg, headers) => {
246
249
  const body = JSON.stringify(object);
247
250
  this.#preparedHeaders ??= {};
248
- this.#preparedHeaders["content-type"] = "application/json; charset=UTF-8";
251
+ this.#preparedHeaders["content-type"] = "application/json";
249
252
  return typeof arg === "number" ? this.#newResponse(body, arg, headers) : this.#newResponse(body, arg);
250
253
  };
251
254
  html = (html, arg, headers) => {
@@ -36,7 +36,8 @@ const stream = (c, cb, onError) => {
36
36
  try {
37
37
  await cb(stream2);
38
38
  } catch (e) {
39
- if (e instanceof Error && onError) {
39
+ if (e === void 0) {
40
+ } else if (e instanceof Error && onError) {
40
41
  await onError(e, stream2);
41
42
  } else {
42
43
  console.error(e);
@@ -18,15 +18,14 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var hono_base_exports = {};
20
20
  __export(hono_base_exports, {
21
- COMPOSED_HANDLER: () => COMPOSED_HANDLER,
22
21
  HonoBase: () => Hono
23
22
  });
24
23
  module.exports = __toCommonJS(hono_base_exports);
25
24
  var import_compose = require("./compose");
26
25
  var import_context = require("./context");
27
26
  var import_router = require("./router");
27
+ var import_constants = require("./utils/constants");
28
28
  var import_url = require("./utils/url");
29
- const COMPOSED_HANDLER = Symbol("composedHandler");
30
29
  const notFoundHandler = (c) => {
31
30
  return c.text("404 Not Found", 404);
32
31
  };
@@ -113,7 +112,7 @@ class Hono {
113
112
  handler = r.handler;
114
113
  } else {
115
114
  handler = async (c, next) => (await (0, import_compose.compose)([], app.errorHandler)(c, () => r.handler(c, next))).res;
116
- handler[COMPOSED_HANDLER] = r.handler;
115
+ handler[import_constants.COMPOSED_HANDLER] = r.handler;
117
116
  }
118
117
  subApp.#addRoute(r.method, r.path, handler);
119
118
  });
@@ -252,6 +251,5 @@ class Hono {
252
251
  }
253
252
  // Annotate the CommonJS export names for ESM import in node:
254
253
  0 && (module.exports = {
255
- COMPOSED_HANDLER,
256
254
  HonoBase
257
255
  });
@@ -71,7 +71,7 @@ const basicAuth = (options, ...users) => {
71
71
  status,
72
72
  headers: {
73
73
  ...headers,
74
- "content-type": "application/json; charset=UTF-8"
74
+ "content-type": "application/json"
75
75
  }
76
76
  });
77
77
  throw new import_http_exception.HTTPException(status, { res });
@@ -49,7 +49,7 @@ const bearerAuth = (options) => {
49
49
  status,
50
50
  headers: {
51
51
  ...headers,
52
- "content-type": "application/json; charset=UTF-8"
52
+ "content-type": "application/json"
53
53
  }
54
54
  });
55
55
  throw new import_http_exception.HTTPException(status, { res });
@@ -22,6 +22,7 @@ __export(router_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(router_exports);
24
24
  var import_router = require("../../router");
25
+ const emptyParams = /* @__PURE__ */ Object.create(null);
25
26
  class PatternRouter {
26
27
  name = "PatternRouter";
27
28
  #routes = [];
@@ -55,7 +56,7 @@ class PatternRouter {
55
56
  if (routeMethod === method || routeMethod === import_router.METHOD_NAME_ALL) {
56
57
  const match = pattern.exec(path);
57
58
  if (match) {
58
- handlers.push([handler, match.groups || /* @__PURE__ */ Object.create(null)]);
59
+ handlers.push([handler, match.groups || emptyParams]);
59
60
  }
60
61
  }
61
62
  }
@@ -23,12 +23,13 @@ __export(node_exports, {
23
23
  module.exports = __toCommonJS(node_exports);
24
24
  var import_router = require("../../router");
25
25
  var import_url = require("../../utils/url");
26
+ const emptyParams = /* @__PURE__ */ Object.create(null);
26
27
  class Node {
27
28
  #methods;
28
29
  #children;
29
30
  #patterns;
30
31
  #order = 0;
31
- #params = /* @__PURE__ */ Object.create(null);
32
+ #params = emptyParams;
32
33
  constructor(method, handler, children) {
33
34
  this.#children = children || /* @__PURE__ */ Object.create(null);
34
35
  this.#methods = [];
@@ -80,20 +81,22 @@ class Node {
80
81
  const processedSet = {};
81
82
  if (handlerSet !== void 0) {
82
83
  handlerSet.params = /* @__PURE__ */ Object.create(null);
83
- for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
84
- const key = handlerSet.possibleKeys[i2];
85
- const processed = processedSet[handlerSet.score];
86
- handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
87
- processedSet[handlerSet.score] = true;
88
- }
89
84
  handlerSets.push(handlerSet);
85
+ if (nodeParams !== emptyParams || params && params !== emptyParams) {
86
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
87
+ const key = handlerSet.possibleKeys[i2];
88
+ const processed = processedSet[handlerSet.score];
89
+ handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
90
+ processedSet[handlerSet.score] = true;
91
+ }
92
+ }
90
93
  }
91
94
  }
92
95
  return handlerSets;
93
96
  }
94
97
  search(method, path) {
95
98
  const handlerSets = [];
96
- this.#params = /* @__PURE__ */ Object.create(null);
99
+ this.#params = emptyParams;
97
100
  const curNode = this;
98
101
  let curNodes = [curNode];
99
102
  const parts = (0, import_url.splitPath)(path);
@@ -109,30 +112,21 @@ class Node {
109
112
  if (isLast) {
110
113
  if (nextNode.#children["*"]) {
111
114
  handlerSets.push(
112
- ...this.#getHandlerSets(
113
- nextNode.#children["*"],
114
- method,
115
- node.#params,
116
- /* @__PURE__ */ Object.create(null)
117
- )
115
+ ...this.#getHandlerSets(nextNode.#children["*"], method, node.#params)
118
116
  );
119
117
  }
120
- handlerSets.push(
121
- ...this.#getHandlerSets(nextNode, method, node.#params, /* @__PURE__ */ Object.create(null))
122
- );
118
+ handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
123
119
  } else {
124
120
  tempNodes.push(nextNode);
125
121
  }
126
122
  }
127
123
  for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
128
124
  const pattern = node.#patterns[k];
129
- const params = { ...node.#params };
125
+ const params = node.#params === emptyParams ? {} : { ...node.#params };
130
126
  if (pattern === "*") {
131
127
  const astNode = node.#children["*"];
132
128
  if (astNode) {
133
- handlerSets.push(
134
- ...this.#getHandlerSets(astNode, method, node.#params, /* @__PURE__ */ Object.create(null))
135
- );
129
+ handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
136
130
  tempNodes.push(astNode);
137
131
  }
138
132
  continue;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var constants_exports = {};
20
+ __export(constants_exports, {
21
+ COMPOSED_HANDLER: () => COMPOSED_HANDLER
22
+ });
23
+ module.exports = __toCommonJS(constants_exports);
24
+ const COMPOSED_HANDLER = "__COMPOSED_HANDLER";
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ COMPOSED_HANDLER
28
+ });
@@ -143,6 +143,9 @@ const _serialize = (name, value, opt = {}) => {
143
143
  if (opt.sameSite) {
144
144
  cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
145
145
  }
146
+ if (opt.priority) {
147
+ cookie += `; Priority=${opt.priority}`;
148
+ }
146
149
  if (opt.partitioned) {
147
150
  if (!opt.secure) {
148
151
  throw new Error("Partitioned Cookie must have Secure attributes");
@@ -22,10 +22,10 @@ __export(handler_exports, {
22
22
  isMiddleware: () => isMiddleware
23
23
  });
24
24
  module.exports = __toCommonJS(handler_exports);
25
- var import_hono_base = require("../hono-base");
25
+ var import_constants = require("./constants");
26
26
  const isMiddleware = (handler) => handler.length > 1;
27
27
  const findTargetHandler = (handler) => {
28
- return handler[import_hono_base.COMPOSED_HANDLER] ? findTargetHandler(handler[import_hono_base.COMPOSED_HANDLER]) : handler;
28
+ return handler[import_constants.COMPOSED_HANDLER] ? findTargetHandler(handler[import_constants.COMPOSED_HANDLER]) : handler;
29
29
  };
30
30
  // Annotate the CommonJS export names for ESM import in node:
31
31
  0 && (module.exports = {
@@ -30,7 +30,7 @@ const getMimeType = (filename, mimes = baseMimes) => {
30
30
  return;
31
31
  }
32
32
  let mimeType = mimes[match[1]];
33
- if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
33
+ if (mimeType && mimeType.startsWith("text")) {
34
34
  mimeType += "; charset=utf-8";
35
35
  }
36
36
  return mimeType;
package/dist/context.js CHANGED
@@ -217,12 +217,15 @@ var Context = class {
217
217
  this.#preparedHeaders = {};
218
218
  }
219
219
  this.#preparedHeaders["content-type"] = TEXT_PLAIN;
220
- return typeof arg === "number" ? this.#newResponse(text, arg, headers) : this.#newResponse(text, arg);
220
+ if (typeof arg === "number") {
221
+ return this.#newResponse(text, arg, headers);
222
+ }
223
+ return this.#newResponse(text, arg);
221
224
  };
222
225
  json = (object, arg, headers) => {
223
226
  const body = JSON.stringify(object);
224
227
  this.#preparedHeaders ??= {};
225
- this.#preparedHeaders["content-type"] = "application/json; charset=UTF-8";
228
+ this.#preparedHeaders["content-type"] = "application/json";
226
229
  return typeof arg === "number" ? this.#newResponse(body, arg, headers) : this.#newResponse(body, arg);
227
230
  };
228
231
  html = (html, arg, headers) => {
@@ -14,7 +14,8 @@ var stream = (c, cb, onError) => {
14
14
  try {
15
15
  await cb(stream2);
16
16
  } catch (e) {
17
- if (e instanceof Error && onError) {
17
+ if (e === void 0) {
18
+ } else if (e instanceof Error && onError) {
18
19
  await onError(e, stream2);
19
20
  } else {
20
21
  console.error(e);
package/dist/hono-base.js CHANGED
@@ -2,8 +2,8 @@
2
2
  import { compose } from "./compose.js";
3
3
  import { Context } from "./context.js";
4
4
  import { METHODS, METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE } from "./router.js";
5
+ import { COMPOSED_HANDLER } from "./utils/constants.js";
5
6
  import { getPath, getPathNoStrict, mergePath } from "./utils/url.js";
6
- var COMPOSED_HANDLER = Symbol("composedHandler");
7
7
  var notFoundHandler = (c) => {
8
8
  return c.text("404 Not Found", 404);
9
9
  };
@@ -228,6 +228,5 @@ var Hono = class {
228
228
  };
229
229
  };
230
230
  export {
231
- COMPOSED_HANDLER,
232
231
  Hono as HonoBase
233
232
  };
@@ -49,7 +49,7 @@ var basicAuth = (options, ...users) => {
49
49
  status,
50
50
  headers: {
51
51
  ...headers,
52
- "content-type": "application/json; charset=UTF-8"
52
+ "content-type": "application/json"
53
53
  }
54
54
  });
55
55
  throw new HTTPException(status, { res });
@@ -27,7 +27,7 @@ var bearerAuth = (options) => {
27
27
  status,
28
28
  headers: {
29
29
  ...headers,
30
- "content-type": "application/json; charset=UTF-8"
30
+ "content-type": "application/json"
31
31
  }
32
32
  });
33
33
  throw new HTTPException(status, { res });
@@ -1,5 +1,6 @@
1
1
  // src/router/pattern-router/router.ts
2
2
  import { METHOD_NAME_ALL, UnsupportedPathError } from "../../router.js";
3
+ var emptyParams = /* @__PURE__ */ Object.create(null);
3
4
  var PatternRouter = class {
4
5
  name = "PatternRouter";
5
6
  #routes = [];
@@ -33,7 +34,7 @@ var PatternRouter = class {
33
34
  if (routeMethod === method || routeMethod === METHOD_NAME_ALL) {
34
35
  const match = pattern.exec(path);
35
36
  if (match) {
36
- handlers.push([handler, match.groups || /* @__PURE__ */ Object.create(null)]);
37
+ handlers.push([handler, match.groups || emptyParams]);
37
38
  }
38
39
  }
39
40
  }
@@ -1,12 +1,13 @@
1
1
  // src/router/trie-router/node.ts
2
2
  import { METHOD_NAME_ALL } from "../../router.js";
3
3
  import { getPattern, splitPath, splitRoutingPath } from "../../utils/url.js";
4
+ var emptyParams = /* @__PURE__ */ Object.create(null);
4
5
  var Node = class {
5
6
  #methods;
6
7
  #children;
7
8
  #patterns;
8
9
  #order = 0;
9
- #params = /* @__PURE__ */ Object.create(null);
10
+ #params = emptyParams;
10
11
  constructor(method, handler, children) {
11
12
  this.#children = children || /* @__PURE__ */ Object.create(null);
12
13
  this.#methods = [];
@@ -58,20 +59,22 @@ var Node = class {
58
59
  const processedSet = {};
59
60
  if (handlerSet !== void 0) {
60
61
  handlerSet.params = /* @__PURE__ */ Object.create(null);
61
- for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
62
- const key = handlerSet.possibleKeys[i2];
63
- const processed = processedSet[handlerSet.score];
64
- handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
65
- processedSet[handlerSet.score] = true;
66
- }
67
62
  handlerSets.push(handlerSet);
63
+ if (nodeParams !== emptyParams || params && params !== emptyParams) {
64
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
65
+ const key = handlerSet.possibleKeys[i2];
66
+ const processed = processedSet[handlerSet.score];
67
+ handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
68
+ processedSet[handlerSet.score] = true;
69
+ }
70
+ }
68
71
  }
69
72
  }
70
73
  return handlerSets;
71
74
  }
72
75
  search(method, path) {
73
76
  const handlerSets = [];
74
- this.#params = /* @__PURE__ */ Object.create(null);
77
+ this.#params = emptyParams;
75
78
  const curNode = this;
76
79
  let curNodes = [curNode];
77
80
  const parts = splitPath(path);
@@ -87,30 +90,21 @@ var Node = class {
87
90
  if (isLast) {
88
91
  if (nextNode.#children["*"]) {
89
92
  handlerSets.push(
90
- ...this.#getHandlerSets(
91
- nextNode.#children["*"],
92
- method,
93
- node.#params,
94
- /* @__PURE__ */ Object.create(null)
95
- )
93
+ ...this.#getHandlerSets(nextNode.#children["*"], method, node.#params)
96
94
  );
97
95
  }
98
- handlerSets.push(
99
- ...this.#getHandlerSets(nextNode, method, node.#params, /* @__PURE__ */ Object.create(null))
100
- );
96
+ handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
101
97
  } else {
102
98
  tempNodes.push(nextNode);
103
99
  }
104
100
  }
105
101
  for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
106
102
  const pattern = node.#patterns[k];
107
- const params = { ...node.#params };
103
+ const params = node.#params === emptyParams ? {} : { ...node.#params };
108
104
  if (pattern === "*") {
109
105
  const astNode = node.#children["*"];
110
106
  if (astNode) {
111
- handlerSets.push(
112
- ...this.#getHandlerSets(astNode, method, node.#params, /* @__PURE__ */ Object.create(null))
113
- );
107
+ handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
114
108
  tempNodes.push(astNode);
115
109
  }
116
110
  continue;
@@ -2,7 +2,7 @@ import { HonoRequest } from './request';
2
2
  import type { Result } from './router';
3
3
  import type { Env, FetchEventLike, H, Input, NotFoundHandler, RouterRoute, TypedResponse } from './types';
4
4
  import type { ResponseHeader } from './utils/headers';
5
- import type { RedirectStatusCode, StatusCode } from './utils/http-status';
5
+ import type { ContentfulStatusCode, RedirectStatusCode, StatusCode } from './utils/http-status';
6
6
  import type { BaseMime } from './utils/mime';
7
7
  import type { InvalidJSONValue, IsAny, JSONParsed, JSONValue, SimplifyDeepArray } from './utils/types';
8
8
  type HeaderRecord = Record<"Content-Type", BaseMime> | Record<ResponseHeader, string | string[]> | Record<string, string | string[]>;
@@ -82,12 +82,16 @@ interface Set<E extends Env> {
82
82
  */
83
83
  interface NewResponse {
84
84
  (data: Data | null, status?: StatusCode, headers?: HeaderRecord): Response;
85
- (data: Data | null, init?: ResponseInit): Response;
85
+ (data: Data | null, init?: ResponseOrInit): Response;
86
86
  }
87
87
  /**
88
88
  * Interface for responding with a body.
89
89
  */
90
- interface BodyRespond extends NewResponse {
90
+ interface BodyRespond {
91
+ (data: Data, status?: ContentfulStatusCode, headers?: HeaderRecord): Response;
92
+ (data: null, status?: StatusCode, headers?: HeaderRecord): Response;
93
+ (data: Data, init?: ResponseOrInit<ContentfulStatusCode>): Response;
94
+ (data: null, init?: ResponseOrInit): Response;
91
95
  }
92
96
  /**
93
97
  * Interface for responding with text.
@@ -103,8 +107,8 @@ interface BodyRespond extends NewResponse {
103
107
  * @returns {Response & TypedResponse<T, U, 'text'>} - The response after rendering the text content, typed with the provided text and status code types.
104
108
  */
105
109
  interface TextRespond {
106
- <T extends string, U extends StatusCode = StatusCode>(text: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<T, U, "text">;
107
- <T extends string, U extends StatusCode = StatusCode>(text: T, init?: ResponseInit): Response & TypedResponse<T, U, "text">;
110
+ <T extends string, U extends ContentfulStatusCode = ContentfulStatusCode>(text: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<T, U, "text">;
111
+ <T extends string, U extends ContentfulStatusCode = ContentfulStatusCode>(text: T, init?: ResponseOrInit<U>): Response & TypedResponse<T, U, "text">;
108
112
  }
109
113
  /**
110
114
  * Interface for responding with JSON.
@@ -120,8 +124,8 @@ interface TextRespond {
120
124
  * @returns {JSONRespondReturn<T, U>} - The response after rendering the JSON object, typed with the provided object and status code types.
121
125
  */
122
126
  interface JSONRespond {
123
- <T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends StatusCode = StatusCode>(object: T, status?: U, headers?: HeaderRecord): JSONRespondReturn<T, U>;
124
- <T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends StatusCode = StatusCode>(object: T, init?: ResponseInit): JSONRespondReturn<T, U>;
127
+ <T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends ContentfulStatusCode = ContentfulStatusCode>(object: T, status?: U, headers?: HeaderRecord): JSONRespondReturn<T, U>;
128
+ <T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends ContentfulStatusCode = ContentfulStatusCode>(object: T, init?: ResponseOrInit<U>): JSONRespondReturn<T, U>;
125
129
  }
126
130
  /**
127
131
  * @template T - The type of the JSON value or simplified unknown type.
@@ -129,7 +133,7 @@ interface JSONRespond {
129
133
  *
130
134
  * @returns {Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? (JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T>) : never, U, 'json'>} - The response after rendering the JSON object, typed with the provided object and status code types.
131
135
  */
132
- type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends StatusCode> = Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T> : never, U, "json">;
136
+ type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends ContentfulStatusCode> = Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T> : never, U, "json">;
133
137
  /**
134
138
  * Interface representing a function that responds with HTML content.
135
139
  *
@@ -141,8 +145,8 @@ type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown> | Invali
141
145
  * @returns A Response object or a Promise that resolves to a Response object.
142
146
  */
143
147
  interface HTMLRespond {
144
- <T extends string | Promise<string>>(html: T, status?: StatusCode, headers?: HeaderRecord): T extends string ? Response : Promise<Response>;
145
- <T extends string | Promise<string>>(html: T, init?: ResponseInit): T extends string ? Response : Promise<Response>;
148
+ <T extends string | Promise<string>>(html: T, status?: ContentfulStatusCode, headers?: HeaderRecord): T extends string ? Response : Promise<Response>;
149
+ <T extends string | Promise<string>>(html: T, init?: ResponseOrInit<ContentfulStatusCode>): T extends string ? Response : Promise<Response>;
146
150
  }
147
151
  /**
148
152
  * Options for configuring the context.
@@ -180,11 +184,12 @@ type ResponseHeadersInit = [
180
184
  string,
181
185
  string
182
186
  ][] | Record<"Content-Type", BaseMime> | Record<ResponseHeader, string> | Record<string, string> | Headers;
183
- interface ResponseInit {
187
+ interface ResponseInit<T extends StatusCode = StatusCode> {
184
188
  headers?: ResponseHeadersInit;
185
- status?: number;
189
+ status?: T;
186
190
  statusText?: string;
187
191
  }
192
+ type ResponseOrInit<T extends StatusCode = StatusCode> = ResponseInit<T> | Response;
188
193
  export declare const TEXT_PLAIN = "text/plain; charset=UTF-8";
189
194
  export declare class Context<E extends Env = any, P extends string = any, I extends Input = {}> {
190
195
  /**
@@ -6,10 +6,6 @@ import { Context } from './context';
6
6
  import type { ExecutionContext } from './context';
7
7
  import type { Router } from './router';
8
8
  import type { Env, ErrorHandler, H, HandlerInterface, MergePath, MergeSchemaPath, MiddlewareHandlerInterface, NotFoundHandler, OnHandlerInterface, RouterRoute, Schema } from './types';
9
- /**
10
- * Symbol used to mark a composed handler.
11
- */
12
- export declare const COMPOSED_HANDLER: unique symbol;
13
9
  type GetPath<E extends Env> = (request: Request, options?: {
14
10
  env?: E["Bindings"];
15
11
  }) => string;
@@ -2,7 +2,7 @@
2
2
  * @module
3
3
  * This module provides the `HTTPException` class.
4
4
  */
5
- import type { StatusCode } from './utils/http-status';
5
+ import type { ContentfulStatusCode } from './utils/http-status';
6
6
  /**
7
7
  * Options for creating an `HTTPException`.
8
8
  * @property res - Optional response object to use.
@@ -42,13 +42,13 @@ type HTTPExceptionOptions = {
42
42
  */
43
43
  export declare class HTTPException extends Error {
44
44
  readonly res?: Response;
45
- readonly status: StatusCode;
45
+ readonly status: ContentfulStatusCode;
46
46
  /**
47
47
  * Creates an instance of `HTTPException`.
48
48
  * @param status - HTTP status code for the exception. Defaults to 500.
49
49
  * @param options - Additional options for the exception.
50
50
  */
51
- constructor(status?: StatusCode, options?: HTTPExceptionOptions);
51
+ constructor(status?: ContentfulStatusCode, options?: HTTPExceptionOptions);
52
52
  /**
53
53
  * Returns the response object associated with the exception.
54
54
  * If a response object is not provided, a new response is created with the error message and status code.
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Constant used to mark a composed handler.
3
+ */
4
+ export declare const COMPOSED_HANDLER = "__COMPOSED_HANDLER";
@@ -29,6 +29,7 @@ export type CookieOptions = {
29
29
  signingSecret?: string;
30
30
  sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
31
31
  partitioned?: boolean;
32
+ priority?: "Low" | "Medium" | "High";
32
33
  prefix?: CookiePrefixOptions;
33
34
  } & PartitionedCookieConstraint;
34
35
  export type CookiePrefixOptions = "host" | "secure";
@@ -28,3 +28,5 @@ export type UnOfficalStatusCode = UnofficialStatusCode;
28
28
  * If you want to use an unofficial status, use `UnofficialStatusCode`.
29
29
  */
30
30
  export type StatusCode = InfoStatusCode | SuccessStatusCode | RedirectStatusCode | ClientErrorStatusCode | ServerErrorStatusCode | UnofficialStatusCode;
31
+ export type ContentlessStatusCode = 101 | 204 | 205 | 304;
32
+ export type ContentfulStatusCode = Exclude<StatusCode, ContentlessStatusCode>;
@@ -0,0 +1,5 @@
1
+ // src/utils/constants.ts
2
+ var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
3
+ export {
4
+ COMPOSED_HANDLER
5
+ };
@@ -118,6 +118,9 @@ var _serialize = (name, value, opt = {}) => {
118
118
  if (opt.sameSite) {
119
119
  cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
120
120
  }
121
+ if (opt.priority) {
122
+ cookie += `; Priority=${opt.priority}`;
123
+ }
121
124
  if (opt.partitioned) {
122
125
  if (!opt.secure) {
123
126
  throw new Error("Partitioned Cookie must have Secure attributes");
@@ -1,5 +1,5 @@
1
1
  // src/utils/handler.ts
2
- import { COMPOSED_HANDLER } from "../hono-base.js";
2
+ import { COMPOSED_HANDLER } from "./constants.js";
3
3
  var isMiddleware = (handler) => handler.length > 1;
4
4
  var findTargetHandler = (handler) => {
5
5
  return handler[COMPOSED_HANDLER] ? findTargetHandler(handler[COMPOSED_HANDLER]) : handler;
@@ -6,7 +6,7 @@ var getMimeType = (filename, mimes = baseMimes) => {
6
6
  return;
7
7
  }
8
8
  let mimeType = mimes[match[1]];
9
- if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
9
+ if (mimeType && mimeType.startsWith("text")) {
10
10
  mimeType += "; charset=utf-8";
11
11
  }
12
12
  return mimeType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.6.13",
3
+ "version": "4.6.15",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",