hono 4.7.4 → 4.7.6

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.
@@ -93,25 +93,31 @@ var EventProcessor = class {
93
93
  const body = isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : await res.text();
94
94
  const result = {
95
95
  body,
96
- headers: {},
97
- multiValueHeaders: event.multiValueHeaders ? {} : void 0,
98
96
  statusCode: res.status,
99
- isBase64Encoded
97
+ isBase64Encoded,
98
+ ...event.multiValueHeaders ? {
99
+ multiValueHeaders: {}
100
+ } : {
101
+ headers: {}
102
+ }
100
103
  };
101
104
  this.setCookies(event, res, result);
102
- res.headers.forEach((value, key) => {
103
- result.headers[key] = value;
104
- if (event.multiValueHeaders && result.multiValueHeaders) {
105
+ if (result.multiValueHeaders) {
106
+ res.headers.forEach((value, key) => {
105
107
  result.multiValueHeaders[key] = [value];
106
- }
107
- });
108
+ });
109
+ } else {
110
+ res.headers.forEach((value, key) => {
111
+ result.headers[key] = value;
112
+ });
113
+ }
108
114
  return result;
109
115
  }
110
116
  setCookies(event, res, result) {
111
117
  if (res.headers.has("set-cookie")) {
112
118
  const cookies = res.headers.getSetCookie ? res.headers.getSetCookie() : Array.from(res.headers.entries()).filter(([k]) => k === "set-cookie").map(([, v]) => v);
113
119
  if (Array.isArray(cookies)) {
114
- this.setCookiesToResult(event, result, cookies);
120
+ this.setCookiesToResult(result, cookies);
115
121
  res.headers.delete("set-cookie");
116
122
  }
117
123
  }
@@ -132,7 +138,7 @@ var EventV2Processor = class extends EventProcessor {
132
138
  headers.set("Cookie", event.cookies.join("; "));
133
139
  }
134
140
  }
135
- setCookiesToResult(_, result, cookies) {
141
+ setCookiesToResult(result, cookies) {
136
142
  result.cookies = cookies;
137
143
  }
138
144
  getHeaders(event) {
@@ -185,7 +191,7 @@ var EventV1Processor = class extends EventProcessor {
185
191
  }
186
192
  return headers;
187
193
  }
188
- setCookiesToResult(_, result, cookies) {
194
+ setCookiesToResult(result, cookies) {
189
195
  result.multiValueHeaders = {
190
196
  "set-cookie": cookies
191
197
  };
@@ -234,8 +240,8 @@ var ALBProcessor = class extends EventProcessor {
234
240
  headers.append("Cookie", cookie);
235
241
  }
236
242
  }
237
- setCookiesToResult(event, result, cookies) {
238
- if (event.multiValueHeaders && result.multiValueHeaders) {
243
+ setCookiesToResult(result, cookies) {
244
+ if (result.multiValueHeaders) {
239
245
  result.multiValueHeaders["set-cookie"] = cookies;
240
246
  } else {
241
247
  result.headers["set-cookie"] = cookies.join(", ");
@@ -123,25 +123,31 @@ class EventProcessor {
123
123
  const body = isBase64Encoded ? (0, import_encode.encodeBase64)(await res.arrayBuffer()) : await res.text();
124
124
  const result = {
125
125
  body,
126
- headers: {},
127
- multiValueHeaders: event.multiValueHeaders ? {} : void 0,
128
126
  statusCode: res.status,
129
- isBase64Encoded
127
+ isBase64Encoded,
128
+ ...event.multiValueHeaders ? {
129
+ multiValueHeaders: {}
130
+ } : {
131
+ headers: {}
132
+ }
130
133
  };
131
134
  this.setCookies(event, res, result);
132
- res.headers.forEach((value, key) => {
133
- result.headers[key] = value;
134
- if (event.multiValueHeaders && result.multiValueHeaders) {
135
+ if (result.multiValueHeaders) {
136
+ res.headers.forEach((value, key) => {
135
137
  result.multiValueHeaders[key] = [value];
136
- }
137
- });
138
+ });
139
+ } else {
140
+ res.headers.forEach((value, key) => {
141
+ result.headers[key] = value;
142
+ });
143
+ }
138
144
  return result;
139
145
  }
140
146
  setCookies(event, res, result) {
141
147
  if (res.headers.has("set-cookie")) {
142
148
  const cookies = res.headers.getSetCookie ? res.headers.getSetCookie() : Array.from(res.headers.entries()).filter(([k]) => k === "set-cookie").map(([, v]) => v);
143
149
  if (Array.isArray(cookies)) {
144
- this.setCookiesToResult(event, result, cookies);
150
+ this.setCookiesToResult(result, cookies);
145
151
  res.headers.delete("set-cookie");
146
152
  }
147
153
  }
@@ -162,7 +168,7 @@ class EventV2Processor extends EventProcessor {
162
168
  headers.set("Cookie", event.cookies.join("; "));
163
169
  }
164
170
  }
165
- setCookiesToResult(_, result, cookies) {
171
+ setCookiesToResult(result, cookies) {
166
172
  result.cookies = cookies;
167
173
  }
168
174
  getHeaders(event) {
@@ -215,7 +221,7 @@ class EventV1Processor extends EventProcessor {
215
221
  }
216
222
  return headers;
217
223
  }
218
- setCookiesToResult(_, result, cookies) {
224
+ setCookiesToResult(result, cookies) {
219
225
  result.multiValueHeaders = {
220
226
  "set-cookie": cookies
221
227
  };
@@ -264,8 +270,8 @@ class ALBProcessor extends EventProcessor {
264
270
  headers.append("Cookie", cookie);
265
271
  }
266
272
  }
267
- setCookiesToResult(event, result, cookies) {
268
- if (event.multiValueHeaders && result.multiValueHeaders) {
273
+ setCookiesToResult(result, cookies) {
274
+ if (result.multiValueHeaders) {
269
275
  result.multiValueHeaders["set-cookie"] = cookies;
270
276
  } else {
271
277
  result.headers["set-cookie"] = cookies.join(", ");
@@ -112,20 +112,21 @@ class ClientRequestImpl {
112
112
  }
113
113
  const hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
114
114
  const parts = [...opts.path];
115
- if (parts.at(-1) === "toString") {
116
- if (parts.at(-2) === "name") {
117
- return parts.at(-3) || "";
115
+ const lastParts = parts.slice(-3).reverse();
116
+ if (lastParts[0] === "toString") {
117
+ if (lastParts[1] === "name") {
118
+ return lastParts[2] || "";
118
119
  }
119
120
  return proxyCallback.toString();
120
121
  }
121
- if (parts.at(-1) === "valueOf") {
122
- if (parts.at(-2) === "name") {
123
- return parts.at(-3) || "";
122
+ if (lastParts[0] === "valueOf") {
123
+ if (lastParts[1] === "name") {
124
+ return lastParts[2] || "";
124
125
  }
125
126
  return proxyCallback;
126
127
  }
127
128
  let method = "";
128
- if (/^\$/.test(parts.at(-1))) {
129
+ if (/^\$/.test(lastParts[0])) {
129
130
  const last = parts.pop();
130
131
  if (last) {
131
132
  method = last.replace(/^\$/, "");
@@ -29,7 +29,7 @@ const compress = (options) => {
29
29
  return async function compress2(ctx, next) {
30
30
  await next();
31
31
  const contentLength = ctx.res.headers.get("Content-Length");
32
- if (ctx.res.headers.has("Content-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) {
32
+ if (ctx.res.headers.has("Content-Encoding") || ctx.res.headers.has("Transfer-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) {
33
33
  return;
34
34
  }
35
35
  const accepted = ctx.req.header("Accept-Encoding");
@@ -97,20 +97,21 @@ var ClientRequestImpl = class {
97
97
  };
98
98
  var hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
99
99
  const parts = [...opts.path];
100
- if (parts.at(-1) === "toString") {
101
- if (parts.at(-2) === "name") {
102
- return parts.at(-3) || "";
100
+ const lastParts = parts.slice(-3).reverse();
101
+ if (lastParts[0] === "toString") {
102
+ if (lastParts[1] === "name") {
103
+ return lastParts[2] || "";
103
104
  }
104
105
  return proxyCallback.toString();
105
106
  }
106
- if (parts.at(-1) === "valueOf") {
107
- if (parts.at(-2) === "name") {
108
- return parts.at(-3) || "";
107
+ if (lastParts[0] === "valueOf") {
108
+ if (lastParts[1] === "name") {
109
+ return lastParts[2] || "";
109
110
  }
110
111
  return proxyCallback;
111
112
  }
112
113
  let method = "";
113
- if (/^\$/.test(parts.at(-1))) {
114
+ if (/^\$/.test(lastParts[0])) {
114
115
  const last = parts.pop();
115
116
  if (last) {
116
117
  method = last.replace(/^\$/, "");
@@ -7,7 +7,7 @@ var compress = (options) => {
7
7
  return async function compress2(ctx, next) {
8
8
  await next();
9
9
  const contentLength = ctx.res.headers.get("Content-Length");
10
- if (ctx.res.headers.has("Content-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) {
10
+ if (ctx.res.headers.has("Content-Encoding") || ctx.res.headers.has("Transfer-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) {
11
11
  return;
12
12
  }
13
13
  const accepted = ctx.req.header("Accept-Encoding");
@@ -55,29 +55,35 @@ export interface ALBProxyEvent {
55
55
  };
56
56
  requestContext: ALBRequestContext;
57
57
  }
58
- export interface APIGatewayProxyResult {
58
+ type WithHeaders = {
59
+ headers: Record<string, string>;
60
+ multiValueHeaders?: undefined;
61
+ };
62
+ type WithMultiValueHeaders = {
63
+ headers?: undefined;
64
+ multiValueHeaders: Record<string, string[]>;
65
+ };
66
+ export type APIGatewayProxyResult = {
59
67
  statusCode: number;
60
68
  statusDescription?: string;
61
69
  body: string;
62
- headers: Record<string, string>;
63
70
  cookies?: string[];
64
- multiValueHeaders?: {
65
- [headerKey: string]: string[];
66
- };
67
71
  isBase64Encoded: boolean;
68
- }
72
+ } & (WithHeaders | WithMultiValueHeaders);
69
73
  export declare const streamHandle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => Handler;
70
74
  /**
71
75
  * Accepts events from API Gateway/ELB(`APIGatewayProxyEvent`) and directly through Function Url(`APIGatewayProxyEventV2`)
72
76
  */
73
- export declare const handle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => ((event: LambdaEvent, lambdaContext?: LambdaContext) => Promise<APIGatewayProxyResult>);
77
+ export declare const handle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => (<L extends LambdaEvent>(event: L, lambdaContext?: LambdaContext) => Promise<APIGatewayProxyResult & (L extends {
78
+ multiValueHeaders: Record<string, string[]>;
79
+ } ? WithMultiValueHeaders : WithHeaders)>);
74
80
  export declare abstract class EventProcessor<E extends LambdaEvent> {
75
81
  protected abstract getPath(event: E): string;
76
82
  protected abstract getMethod(event: E): string;
77
83
  protected abstract getQueryString(event: E): string;
78
84
  protected abstract getHeaders(event: E): Headers;
79
85
  protected abstract getCookies(event: E, headers: Headers): void;
80
- protected abstract setCookiesToResult(event: E, result: APIGatewayProxyResult, cookies: string[]): void;
86
+ protected abstract setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void;
81
87
  createRequest(event: E): Request;
82
88
  createResult(event: E, res: Response): Promise<APIGatewayProxyResult>;
83
89
  setCookies(event: E, res: Response, result: APIGatewayProxyResult): void;
@@ -87,7 +93,7 @@ export declare class EventV2Processor extends EventProcessor<APIGatewayProxyEven
87
93
  protected getMethod(event: APIGatewayProxyEventV2): string;
88
94
  protected getQueryString(event: APIGatewayProxyEventV2): string;
89
95
  protected getCookies(event: APIGatewayProxyEventV2, headers: Headers): void;
90
- protected setCookiesToResult(_: APIGatewayProxyEventV2, result: APIGatewayProxyResult, cookies: string[]): void;
96
+ protected setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void;
91
97
  protected getHeaders(event: APIGatewayProxyEventV2): Headers;
92
98
  }
93
99
  export declare class EventV1Processor extends EventProcessor<Exclude<LambdaEvent, APIGatewayProxyEventV2>> {
@@ -96,7 +102,7 @@ export declare class EventV1Processor extends EventProcessor<Exclude<LambdaEvent
96
102
  protected getQueryString(event: Exclude<LambdaEvent, APIGatewayProxyEventV2>): string;
97
103
  protected getCookies(event: Exclude<LambdaEvent, APIGatewayProxyEventV2>, headers: Headers): void;
98
104
  protected getHeaders(event: APIGatewayProxyEvent): Headers;
99
- protected setCookiesToResult(_: APIGatewayProxyEvent, result: APIGatewayProxyResult, cookies: string[]): void;
105
+ protected setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void;
100
106
  }
101
107
  export declare class ALBProcessor extends EventProcessor<ALBProxyEvent> {
102
108
  protected getHeaders(event: ALBProxyEvent): Headers;
@@ -104,8 +110,9 @@ export declare class ALBProcessor extends EventProcessor<ALBProxyEvent> {
104
110
  protected getMethod(event: ALBProxyEvent): string;
105
111
  protected getQueryString(event: ALBProxyEvent): string;
106
112
  protected getCookies(event: ALBProxyEvent, headers: Headers): void;
107
- protected setCookiesToResult(event: ALBProxyEvent, result: APIGatewayProxyResult, cookies: string[]): void;
113
+ protected setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void;
108
114
  }
109
115
  export declare const getProcessor: (event: LambdaEvent) => EventProcessor<LambdaEvent>;
110
116
  export declare const isContentTypeBinary: (contentType: string) => boolean;
111
117
  export declare const isContentEncodingBinary: (contentEncoding: string | null) => boolean;
118
+ export {};
@@ -5,4 +5,5 @@
5
5
  export { serveStatic } from './serve-static';
6
6
  export { bunFileSystemModule, toSSG } from './ssg';
7
7
  export { createBunWebSocket } from './websocket';
8
+ export type { BunWebSocketData, BunWebSocketHandler } from './websocket';
8
9
  export { getConnInfo } from './conninfo';
@@ -1,15 +1,15 @@
1
1
  import type { Context } from './context';
2
- import type { Env, ErrorHandler, NotFoundHandler } from './types';
2
+ import type { Env, ErrorHandler, Next, NotFoundHandler } from './types';
3
3
  /**
4
4
  * Compose middleware functions into a single function based on `koa-compose` package.
5
5
  *
6
6
  * @template E - The environment type.
7
7
  *
8
- * @param {[[Function, unknown], ParamIndexMap | Params][]} middleware - An array of middleware functions and their corresponding parameters.
8
+ * @param {[[Function, unknown], unknown][] | [[Function]][]} middleware - An array of middleware functions and their corresponding parameters.
9
9
  * @param {ErrorHandler<E>} [onError] - An optional error handler function.
10
10
  * @param {NotFoundHandler<E>} [onNotFound] - An optional not-found handler function.
11
11
  *
12
- * @returns {(context: Context, next?: Function) => Promise<>} - A composed middleware function.
12
+ * @returns {(context: Context, next?: Next) => Promise<Context>} - A composed middleware function.
13
13
  */
14
14
  export declare const compose: <E extends Env = Env>(middleware: [
15
15
  [
@@ -21,4 +21,4 @@ export declare const compose: <E extends Env = Env>(middleware: [
21
21
  [
22
22
  Function
23
23
  ]
24
- ][], onError?: ErrorHandler<E>, onNotFound?: NotFoundHandler<E>) => ((context: Context, next?: Function) => Promise<Context>);
24
+ ][], onError?: ErrorHandler<E>, onNotFound?: NotFoundHandler<E>) => ((context: Context, next?: Next) => Promise<Context>);
@@ -339,7 +339,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
339
339
  * @example
340
340
  * ```ts
341
341
  * app.use('*', async (c, next) => {
342
- * c.set('message', 'Hono is cool!!')
342
+ * c.set('message', 'Hono is hot!!')
343
343
  * await next()
344
344
  * })
345
345
  * ```
@@ -6,7 +6,7 @@ import type { Context } from '../../context';
6
6
  export type Runtime = "node" | "deno" | "bun" | "workerd" | "fastly" | "edge-light" | "other";
7
7
  export declare const env: <T extends Record<string, unknown>, C extends Context = Context<{
8
8
  Bindings: T;
9
- }>>(c: T extends Record<string, unknown> ? Context : C, runtime?: Runtime) => T & C["env"];
9
+ }, any, {}>>(c: T extends Record<string, unknown> ? Context : C, runtime?: Runtime) => T & C["env"];
10
10
  export declare const knownUserAgents: Partial<Record<Runtime, string>>;
11
11
  export declare const getRuntimeKey: () => Runtime;
12
12
  export declare const checkUserAgentEquals: (platform: string) => boolean;
@@ -40,7 +40,7 @@ type BasicAuthOptions = {
40
40
  * '/auth/*',
41
41
  * basicAuth({
42
42
  * username: 'hono',
43
- * password: 'acoolproject',
43
+ * password: 'ahotproject',
44
44
  * })
45
45
  * )
46
46
  *
@@ -47,7 +47,7 @@ type BearerAuthOptions = {
47
47
  * ```ts
48
48
  * const app = new Hono()
49
49
  *
50
- * const token = 'honoiscool'
50
+ * const token = 'honoishot'
51
51
  *
52
52
  * app.use('/api/*', bearerAuth({ token }))
53
53
  *
@@ -24,7 +24,7 @@ import type { Env, MiddlewareHandler } from '../../types';
24
24
  * app.use(contextStorage())
25
25
  *
26
26
  * app.use(async (c, next) => {
27
- * c.set('message', 'Hono is cool!!)
27
+ * c.set('message', 'Hono is hot!!)
28
28
  * await next()
29
29
  * })
30
30
  *
@@ -34,7 +34,7 @@ export declare const RETAINED_304_HEADERS: string[];
34
34
  *
35
35
  * app.use('/etag/*', etag())
36
36
  * app.get('/etag/abc', (c) => {
37
- * return c.text('Hono is cool')
37
+ * return c.text('Hono is hot')
38
38
  * })
39
39
  * ```
40
40
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.7.4",
3
+ "version": "4.7.6",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",