hono 4.7.4 → 4.7.5

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(", ");
@@ -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>);
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.7.4",
3
+ "version": "4.7.5",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",