hono 3.10.1 → 3.10.3

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.
@@ -44,7 +44,7 @@ const compose = (middleware, onError, onNotFound) => {
44
44
  }
45
45
  if (!handler) {
46
46
  if (context instanceof import_context.Context && context.finalized === false && onNotFound) {
47
- res = onNotFound(context);
47
+ res = await onNotFound(context);
48
48
  }
49
49
  } else {
50
50
  try {
@@ -54,7 +54,7 @@ const compose = (middleware, onError, onNotFound) => {
54
54
  } catch (err) {
55
55
  if (err instanceof Error && context instanceof import_context.Context && onError) {
56
56
  context.error = err;
57
- res = onError(err, context);
57
+ res = await onError(err, context);
58
58
  isError = true;
59
59
  } else {
60
60
  throw err;
@@ -53,11 +53,11 @@ const getSignedCookie = async (c, secret, key) => {
53
53
  return obj;
54
54
  };
55
55
  const setCookie = (c, name, value, opt) => {
56
- const cookie = (0, import_cookie.serialize)(name, value, opt);
56
+ const cookie = (0, import_cookie.serialize)(name, value, { path: "/", ...opt });
57
57
  c.header("set-cookie", cookie, { append: true });
58
58
  };
59
59
  const setSignedCookie = async (c, name, value, secret, opt) => {
60
- const cookie = await (0, import_cookie.serializeSigned)(name, value, secret, opt);
60
+ const cookie = await (0, import_cookie.serializeSigned)(name, value, secret, { path: "/", ...opt });
61
61
  c.header("set-cookie", cookie, { append: true });
62
62
  };
63
63
  const deleteCookie = (c, name, opt) => {
@@ -212,7 +212,7 @@ class Hono extends defineDynamicClass() {
212
212
  }
213
213
  const path = this.getPath(request, { env });
214
214
  const [handlers, paramStash] = this.matchRoute(method, path);
215
- const c = new import_context.Context(new import_request.HonoRequest(request, path, paramStash || []), {
215
+ const c = new import_context.Context(new import_request.HonoRequest(request, path, paramStash), {
216
216
  env,
217
217
  executionCtx,
218
218
  notFoundHandler: this.notFoundHandler
@@ -122,9 +122,9 @@ class JSXNode {
122
122
  buffer[0] += ` ${key}="`;
123
123
  (0, import_html2.escapeToBuffer)(v, buffer);
124
124
  buffer[0] += '"';
125
- } else if (typeof v === "number") {
126
- buffer[0] += ` ${key}="${v}"`;
127
125
  } else if (v === null || v === void 0) {
126
+ } else if (typeof v === "number" || v.isEscaped) {
127
+ buffer[0] += ` ${key}="${v}"`;
128
128
  } else if (typeof v === "boolean" && booleanAttributes.includes(key)) {
129
129
  if (v) {
130
130
  buffer[0] += ` ${key}=""`;
@@ -25,7 +25,7 @@ var import_body = require("./utils/body");
25
25
  var import_cookie = require("./utils/cookie");
26
26
  var import_url = require("./utils/url");
27
27
  class HonoRequest {
28
- constructor(request, path = "/", paramStash = []) {
28
+ constructor(request, path = "/", paramStash = void 0) {
29
29
  this._p = {};
30
30
  this.bodyCache = {};
31
31
  this.cachedBody = (key) => {
@@ -49,24 +49,21 @@ class HonoRequest {
49
49
  this._p = params;
50
50
  }
51
51
  param(key) {
52
- if (this._s) {
53
- if (key) {
54
- const param = this._s[this._p[key]] ?? this._p[key];
55
- return param ? /\%/.test(param) ? (0, import_url.decodeURIComponent_)(param) : param : void 0;
56
- } else {
57
- const decoded = {};
58
- const keys = Object.keys(this._p);
59
- for (let i = 0, len = keys.length; i < len; i++) {
60
- const key2 = keys[i];
61
- const value = this._s[this._p[key2]] ?? this._p[key2];
62
- if (value && typeof value === "string") {
63
- decoded[key2] = /\%/.test(value) ? (0, import_url.decodeURIComponent_)(value) : value;
64
- }
52
+ if (key) {
53
+ const param = this._s ? this._s[this._p[key]] : this._p[key];
54
+ return param ? /\%/.test(param) ? (0, import_url.decodeURIComponent_)(param) : param : void 0;
55
+ } else {
56
+ const decoded = {};
57
+ const keys = Object.keys(this._p);
58
+ for (let i = 0, len = keys.length; i < len; i++) {
59
+ const key2 = keys[i];
60
+ const value = this._s ? this._s[this._p[key2]] : this._p[key2];
61
+ if (value && typeof value === "string") {
62
+ decoded[key2] = /\%/.test(value) ? (0, import_url.decodeURIComponent_)(value) : value;
65
63
  }
66
- return decoded;
67
64
  }
65
+ return decoded;
68
66
  }
69
- return null;
70
67
  }
71
68
  query(key) {
72
69
  return (0, import_url.getQueryParam)(this.url, key);
@@ -26,13 +26,21 @@ var import_buffer = require("../utils/buffer");
26
26
  const validator = (target, validationFunc) => {
27
27
  return async (c, next) => {
28
28
  let value = {};
29
+ const contentType = c.req.header("Content-Type");
29
30
  switch (target) {
30
31
  case "json":
32
+ if (!contentType || !contentType.startsWith("application/json")) {
33
+ const message = `Invalid HTTP header: Content-Type=${contentType}`;
34
+ console.error(message);
35
+ return c.json(
36
+ {
37
+ success: false,
38
+ message
39
+ },
40
+ 400
41
+ );
42
+ }
31
43
  try {
32
- const contentType = c.req.header("Content-Type");
33
- if (!contentType || !contentType.startsWith("application/json")) {
34
- throw new Error(`Invalid HTTP header: Content-Type=${contentType}`);
35
- }
36
44
  const arrayBuffer = c.req.bodyCache.arrayBuffer ?? await c.req.raw.arrayBuffer();
37
45
  value = await new Response(arrayBuffer).json();
38
46
  c.req.bodyCache.json = value;
@@ -50,10 +58,10 @@ const validator = (target, validationFunc) => {
50
58
  break;
51
59
  case "form": {
52
60
  try {
53
- const contentType = c.req.header("Content-Type");
54
- if (contentType) {
61
+ const contentType2 = c.req.header("Content-Type");
62
+ if (contentType2) {
55
63
  const arrayBuffer = c.req.bodyCache.arrayBuffer ?? await c.req.raw.arrayBuffer();
56
- const formData = await (0, import_buffer.bufferToFormData)(arrayBuffer, contentType);
64
+ const formData = await (0, import_buffer.bufferToFormData)(arrayBuffer, contentType2);
57
65
  const form = {};
58
66
  formData.forEach((value2, key) => {
59
67
  form[key] = value2;
package/dist/compose.js CHANGED
@@ -22,7 +22,7 @@ var compose = (middleware, onError, onNotFound) => {
22
22
  }
23
23
  if (!handler) {
24
24
  if (context instanceof Context && context.finalized === false && onNotFound) {
25
- res = onNotFound(context);
25
+ res = await onNotFound(context);
26
26
  }
27
27
  } else {
28
28
  try {
@@ -32,7 +32,7 @@ var compose = (middleware, onError, onNotFound) => {
32
32
  } catch (err) {
33
33
  if (err instanceof Error && context instanceof Context && onError) {
34
34
  context.error = err;
35
- res = onError(err, context);
35
+ res = await onError(err, context);
36
36
  isError = true;
37
37
  } else {
38
38
  throw err;
@@ -27,11 +27,11 @@ var getSignedCookie = async (c, secret, key) => {
27
27
  return obj;
28
28
  };
29
29
  var setCookie = (c, name, value, opt) => {
30
- const cookie = serialize(name, value, opt);
30
+ const cookie = serialize(name, value, { path: "/", ...opt });
31
31
  c.header("set-cookie", cookie, { append: true });
32
32
  };
33
33
  var setSignedCookie = async (c, name, value, secret, opt) => {
34
- const cookie = await serializeSigned(name, value, secret, opt);
34
+ const cookie = await serializeSigned(name, value, secret, { path: "/", ...opt });
35
35
  c.header("set-cookie", cookie, { append: true });
36
36
  };
37
37
  var deleteCookie = (c, name, opt) => {
package/dist/hono-base.js CHANGED
@@ -190,7 +190,7 @@ var Hono = class extends defineDynamicClass() {
190
190
  }
191
191
  const path = this.getPath(request, { env });
192
192
  const [handlers, paramStash] = this.matchRoute(method, path);
193
- const c = new Context(new HonoRequest(request, path, paramStash || []), {
193
+ const c = new Context(new HonoRequest(request, path, paramStash), {
194
194
  env,
195
195
  executionCtx,
196
196
  notFoundHandler: this.notFoundHandler
package/dist/jsx/index.js CHANGED
@@ -95,9 +95,9 @@ var JSXNode = class {
95
95
  buffer[0] += ` ${key}="`;
96
96
  escapeToBuffer(v, buffer);
97
97
  buffer[0] += '"';
98
- } else if (typeof v === "number") {
99
- buffer[0] += ` ${key}="${v}"`;
100
98
  } else if (v === null || v === void 0) {
99
+ } else if (typeof v === "number" || v.isEscaped) {
100
+ buffer[0] += ` ${key}="${v}"`;
101
101
  } else if (typeof v === "boolean" && booleanAttributes.includes(key)) {
102
102
  if (v) {
103
103
  buffer[0] += ` ${key}=""`;
package/dist/request.js CHANGED
@@ -3,7 +3,7 @@ import { parseBody } from "./utils/body.js";
3
3
  import { parse } from "./utils/cookie.js";
4
4
  import { getQueryParam, getQueryParams, decodeURIComponent_ } from "./utils/url.js";
5
5
  var HonoRequest = class {
6
- constructor(request, path = "/", paramStash = []) {
6
+ constructor(request, path = "/", paramStash = void 0) {
7
7
  this._p = {};
8
8
  this.bodyCache = {};
9
9
  this.cachedBody = (key) => {
@@ -27,24 +27,21 @@ var HonoRequest = class {
27
27
  this._p = params;
28
28
  }
29
29
  param(key) {
30
- if (this._s) {
31
- if (key) {
32
- const param = this._s[this._p[key]] ?? this._p[key];
33
- return param ? /\%/.test(param) ? decodeURIComponent_(param) : param : void 0;
34
- } else {
35
- const decoded = {};
36
- const keys = Object.keys(this._p);
37
- for (let i = 0, len = keys.length; i < len; i++) {
38
- const key2 = keys[i];
39
- const value = this._s[this._p[key2]] ?? this._p[key2];
40
- if (value && typeof value === "string") {
41
- decoded[key2] = /\%/.test(value) ? decodeURIComponent_(value) : value;
42
- }
30
+ if (key) {
31
+ const param = this._s ? this._s[this._p[key]] : this._p[key];
32
+ return param ? /\%/.test(param) ? decodeURIComponent_(param) : param : void 0;
33
+ } else {
34
+ const decoded = {};
35
+ const keys = Object.keys(this._p);
36
+ for (let i = 0, len = keys.length; i < len; i++) {
37
+ const key2 = keys[i];
38
+ const value = this._s ? this._s[this._p[key2]] : this._p[key2];
39
+ if (value && typeof value === "string") {
40
+ decoded[key2] = /\%/.test(value) ? decodeURIComponent_(value) : value;
43
41
  }
44
- return decoded;
45
42
  }
43
+ return decoded;
46
44
  }
47
- return null;
48
45
  }
49
46
  query(key) {
50
47
  return getQueryParam(this.url, key);
@@ -32,7 +32,7 @@ export interface LambdaFunctionUrlEvent {
32
32
  isBase64Encoded: boolean;
33
33
  requestContext: LambdaFunctionUrlRequestContext;
34
34
  }
35
- interface APIGatewayProxyResult {
35
+ export interface APIGatewayProxyResult {
36
36
  statusCode: number;
37
37
  body: string;
38
38
  headers: Record<string, string>;
@@ -49,4 +49,3 @@ export declare const streamHandle: <E extends Env = Env, S extends Schema = {},
49
49
  export declare const handle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => (event: APIGatewayProxyEvent | APIGatewayProxyEventV2 | LambdaFunctionUrlEvent, lambdaContext?: LambdaContext) => Promise<APIGatewayProxyResult>;
50
50
  export declare const isContentTypeBinary: (contentType: string) => boolean;
51
51
  export declare const isContentEncodingBinary: (contentEncoding: string | null) => boolean;
52
- export {};
@@ -1,3 +1,4 @@
1
1
  export { handle, streamHandle } from './handler';
2
+ export type { APIGatewayProxyResult } from './handler';
2
3
  export type { ApiGatewayRequestContext, LambdaFunctionUrlRequestContext } from './custom-context';
3
4
  export type { LambdaContext } from './types';
@@ -20,7 +20,7 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
20
20
  private _p;
21
21
  path: string;
22
22
  bodyCache: BodyCache;
23
- constructor(request: Request, path?: string, paramStash?: ParamStash);
23
+ constructor(request: Request, path?: string, paramStash?: ParamStash | undefined);
24
24
  setParams(params: ParamIndexMap | Params): void;
25
25
  param<P2 extends string = P>(key: RemoveQuestion<ParamKeys<P2>>): UndefinedIfHavingQuestion<ParamKeys<P2>>;
26
26
  param<P2 extends string = P>(): UnionToIntersection<ParamKeyToRecord<ParamKeys<P2>>>;
@@ -25,7 +25,7 @@ export interface HandlerInterface<E extends Env = Env, M extends string = string
25
25
  <P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, I extends Input = {}, R extends HandlerResponse<any> = any, E2 extends Env = E>(handler: H<E2, P, I, R>): Hono<E & E2, S & ToSchema<M, P, I['in'], MergeTypedResponseData<R>>, BasePath>;
26
26
  <P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, I extends Input = {}, R extends HandlerResponse<any> = any, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>>(...handlers: [H<E2, P, I, R>, H<E3, P, I, R>]): Hono<E & E2 & E3, S & ToSchema<M, P, I['in'], MergeTypedResponseData<R>>, BasePath>;
27
27
  <P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, R extends HandlerResponse<any> = any, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, E2 extends Env = E, E3 extends Env = E, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>>(...handlers: [H<E2, P, I, R>, H<E3, P, I2, R>, H<E4, P, I3, R>]): Hono<E & E2 & E3 & E4, S & ToSchema<M, P, I3['in'], MergeTypedResponseData<R>>, BasePath>;
28
- <P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, R extends HandlerResponse<any> = any, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>>(...handlers: [H<E2, P, I, R>, H<E3, P, I2, R>, H<E4, P, I3, R>, H<E5, P, I3, R>]): Hono<E & E2 & E3 & E4 & E5, S & ToSchema<M, P, I4['in'], MergeTypedResponseData<R>>, BasePath>;
28
+ <P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, R extends HandlerResponse<any> = any, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>>(...handlers: [H<E2, P, I, R>, H<E3, P, I2, R>, H<E4, P, I3, R>, H<E5, P, I4, R>]): Hono<E & E2 & E3 & E4 & E5, S & ToSchema<M, P, I4['in'], MergeTypedResponseData<R>>, BasePath>;
29
29
  <P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, R extends HandlerResponse<any> = any, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I2 & I3, I5 extends Input = I & I2 & I3 & I4, E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>>(...handlers: [
30
30
  H<E2, P, I, R>,
31
31
  H<E3, P, I2, R>,
@@ -4,13 +4,21 @@ import { bufferToFormData } from "../utils/buffer.js";
4
4
  var validator = (target, validationFunc) => {
5
5
  return async (c, next) => {
6
6
  let value = {};
7
+ const contentType = c.req.header("Content-Type");
7
8
  switch (target) {
8
9
  case "json":
10
+ if (!contentType || !contentType.startsWith("application/json")) {
11
+ const message = `Invalid HTTP header: Content-Type=${contentType}`;
12
+ console.error(message);
13
+ return c.json(
14
+ {
15
+ success: false,
16
+ message
17
+ },
18
+ 400
19
+ );
20
+ }
9
21
  try {
10
- const contentType = c.req.header("Content-Type");
11
- if (!contentType || !contentType.startsWith("application/json")) {
12
- throw new Error(`Invalid HTTP header: Content-Type=${contentType}`);
13
- }
14
22
  const arrayBuffer = c.req.bodyCache.arrayBuffer ?? await c.req.raw.arrayBuffer();
15
23
  value = await new Response(arrayBuffer).json();
16
24
  c.req.bodyCache.json = value;
@@ -28,10 +36,10 @@ var validator = (target, validationFunc) => {
28
36
  break;
29
37
  case "form": {
30
38
  try {
31
- const contentType = c.req.header("Content-Type");
32
- if (contentType) {
39
+ const contentType2 = c.req.header("Content-Type");
40
+ if (contentType2) {
33
41
  const arrayBuffer = c.req.bodyCache.arrayBuffer ?? await c.req.raw.arrayBuffer();
34
- const formData = await bufferToFormData(arrayBuffer, contentType);
42
+ const formData = await bufferToFormData(arrayBuffer, contentType2);
35
43
  const form = {};
36
44
  formData.forEach((value2, key) => {
37
45
  form[key] = value2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "3.10.1",
3
+ "version": "3.10.3",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",