hono 3.6.0 → 3.6.1

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.
@@ -24,43 +24,38 @@ __export(adapter_exports, {
24
24
  module.exports = __toCommonJS(adapter_exports);
25
25
  const env = (c) => {
26
26
  const global = globalThis;
27
- if (c.runtime === "bun" || c.runtime === "node" || c.runtime === "edge-light" || c.runtime === "lagon") {
28
- return global?.process?.env;
29
- }
30
- if (c.runtime === "deno") {
31
- return Deno.env.toObject();
32
- }
33
- if (c.runtime === "workerd") {
34
- return c.env;
35
- }
36
- if (c.runtime === "fastly") {
37
- return {};
38
- }
39
- return {};
27
+ const globalEnv = global?.process?.env;
28
+ const runtime = getRuntimeKey();
29
+ const runtimeEnvHandlers = {
30
+ bun: () => globalEnv,
31
+ node: () => globalEnv,
32
+ "edge-light": () => globalEnv,
33
+ lagon: () => globalEnv,
34
+ deno: () => {
35
+ return Deno.env.toObject();
36
+ },
37
+ workerd: () => c.env,
38
+ fastly: () => ({}),
39
+ other: () => ({})
40
+ };
41
+ return runtimeEnvHandlers[runtime]();
40
42
  };
41
43
  const getRuntimeKey = () => {
42
44
  const global = globalThis;
43
- if (global?.Deno !== void 0) {
45
+ if (global?.Deno !== void 0)
44
46
  return "deno";
45
- }
46
- if (global?.Bun !== void 0) {
47
+ if (global?.Bun !== void 0)
47
48
  return "bun";
48
- }
49
- if (typeof global?.WebSocketPair === "function") {
49
+ if (typeof global?.WebSocketPair === "function")
50
50
  return "workerd";
51
- }
52
- if (typeof global?.EdgeRuntime === "string") {
51
+ if (typeof global?.EdgeRuntime === "string")
53
52
  return "edge-light";
54
- }
55
- if (global?.fastly !== void 0) {
53
+ if (global?.fastly !== void 0)
56
54
  return "fastly";
57
- }
58
- if (global?.__lagon__ !== void 0) {
55
+ if (global?.__lagon__ !== void 0)
59
56
  return "lagon";
60
- }
61
- if (global?.process?.release?.name === "node") {
57
+ if (global?.process?.release?.name === "node")
62
58
  return "node";
63
- }
64
59
  return "other";
65
60
  };
66
61
  // Annotate the CommonJS export names for ESM import in node:
@@ -60,17 +60,17 @@ class Hono extends defineDynamicClass() {
60
60
  this.fetch = (request, Env, executionCtx) => {
61
61
  return this.dispatch(request, executionCtx, Env, request.method);
62
62
  };
63
- this.request = (input, requestInit) => {
63
+ this.request = (input, requestInit, Env, executionCtx) => {
64
64
  if (input instanceof Request) {
65
65
  if (requestInit !== void 0) {
66
66
  input = new Request(input, requestInit);
67
67
  }
68
- return this.fetch(input);
68
+ return this.fetch(input, Env, executionCtx);
69
69
  }
70
70
  input = input.toString();
71
71
  const path = /^https?:\/\//.test(input) ? input : `http://localhost${(0, import_url.mergePath)("/", input)}`;
72
72
  const req = new Request(path, requestInit);
73
- return this.fetch(req);
73
+ return this.fetch(req, Env, executionCtx);
74
74
  };
75
75
  this.fire = () => {
76
76
  addEventListener("fetch", (event) => {
@@ -1,43 +1,38 @@
1
1
  // src/helper/adapter/index.ts
2
2
  var env = (c) => {
3
3
  const global = globalThis;
4
- if (c.runtime === "bun" || c.runtime === "node" || c.runtime === "edge-light" || c.runtime === "lagon") {
5
- return global?.process?.env;
6
- }
7
- if (c.runtime === "deno") {
8
- return Deno.env.toObject();
9
- }
10
- if (c.runtime === "workerd") {
11
- return c.env;
12
- }
13
- if (c.runtime === "fastly") {
14
- return {};
15
- }
16
- return {};
4
+ const globalEnv = global?.process?.env;
5
+ const runtime = getRuntimeKey();
6
+ const runtimeEnvHandlers = {
7
+ bun: () => globalEnv,
8
+ node: () => globalEnv,
9
+ "edge-light": () => globalEnv,
10
+ lagon: () => globalEnv,
11
+ deno: () => {
12
+ return Deno.env.toObject();
13
+ },
14
+ workerd: () => c.env,
15
+ fastly: () => ({}),
16
+ other: () => ({})
17
+ };
18
+ return runtimeEnvHandlers[runtime]();
17
19
  };
18
20
  var getRuntimeKey = () => {
19
21
  const global = globalThis;
20
- if (global?.Deno !== void 0) {
22
+ if (global?.Deno !== void 0)
21
23
  return "deno";
22
- }
23
- if (global?.Bun !== void 0) {
24
+ if (global?.Bun !== void 0)
24
25
  return "bun";
25
- }
26
- if (typeof global?.WebSocketPair === "function") {
26
+ if (typeof global?.WebSocketPair === "function")
27
27
  return "workerd";
28
- }
29
- if (typeof global?.EdgeRuntime === "string") {
28
+ if (typeof global?.EdgeRuntime === "string")
30
29
  return "edge-light";
31
- }
32
- if (global?.fastly !== void 0) {
30
+ if (global?.fastly !== void 0)
33
31
  return "fastly";
34
- }
35
- if (global?.__lagon__ !== void 0) {
32
+ if (global?.__lagon__ !== void 0)
36
33
  return "lagon";
37
- }
38
- if (global?.process?.release?.name === "node") {
34
+ if (global?.process?.release?.name === "node")
39
35
  return "node";
40
- }
41
36
  return "other";
42
37
  };
43
38
  export {
package/dist/hono-base.js CHANGED
@@ -38,17 +38,17 @@ var Hono = class extends defineDynamicClass() {
38
38
  this.fetch = (request, Env, executionCtx) => {
39
39
  return this.dispatch(request, executionCtx, Env, request.method);
40
40
  };
41
- this.request = (input, requestInit) => {
41
+ this.request = (input, requestInit, Env, executionCtx) => {
42
42
  if (input instanceof Request) {
43
43
  if (requestInit !== void 0) {
44
44
  input = new Request(input, requestInit);
45
45
  }
46
- return this.fetch(input);
46
+ return this.fetch(input, Env, executionCtx);
47
47
  }
48
48
  input = input.toString();
49
49
  const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`;
50
50
  const req = new Request(path, requestInit);
51
- return this.fetch(req);
51
+ return this.fetch(req, Env, executionCtx);
52
52
  };
53
53
  this.fire = () => {
54
54
  addEventListener("fetch", (event) => {
@@ -1,3 +1,3 @@
1
1
  import type { ServeStaticOptions } from './serve-static';
2
- declare const module: (options?: ServeStaticOptions) => import("../..").MiddlewareHandler<any, any, {}>;
2
+ declare const module: (options?: ServeStaticOptions) => import("../..").MiddlewareHandler<{}, any, {}>;
3
3
  export { module as serveStatic };
@@ -1,9 +1,10 @@
1
1
  import type { Hono } from '../hono';
2
2
  import type { Schema } from '../types';
3
3
  import type { RemoveBlankRecord } from '../utils/types';
4
+ declare type HonoRequest = typeof Hono.prototype['request'];
4
5
  export declare type ClientRequestOptions = {
5
6
  headers?: Record<string, string>;
6
- fetch?: typeof fetch;
7
+ fetch?: typeof fetch | HonoRequest;
7
8
  };
8
9
  declare type ClientRequest<S extends Schema> = {
9
10
  [M in keyof S]: S[M] extends {
@@ -64,13 +64,13 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
64
64
  private handleError;
65
65
  private dispatch;
66
66
  /**
67
- * @deprecate
67
+ * @deprecated
68
68
  * `app.handleEvent()` will be removed in v4.
69
69
  * Use `app.fetch()` instead of `app.handleEvent()`.
70
70
  */
71
71
  handleEvent: (event: FetchEventLike) => Response | Promise<Response>;
72
72
  fetch: (request: Request, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
73
- request: (input: Request | string | URL, requestInit?: RequestInit) => Response | Promise<Response>;
73
+ request: (input: RequestInfo | URL, requestInit?: RequestInit, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
74
74
  fire: () => void;
75
75
  }
76
76
  export { Hono as HonoBase };
@@ -17,7 +17,7 @@ export declare type Input = {
17
17
  };
18
18
  declare type HandlerResponse<O> = Response | TypedResponse<O> | Promise<Response | TypedResponse<O>>;
19
19
  export declare type Handler<E extends Env = any, P extends string = any, I extends Input = Input, R extends HandlerResponse<any> = any> = (c: Context<E, P, I>, next: Next) => R;
20
- export declare type MiddlewareHandler<E extends Env = any, P extends string = any, I extends Input = {}> = (c: Context<E, P, I>, next: Next) => Promise<Response | void>;
20
+ export declare type MiddlewareHandler<E extends Env = {}, P extends string = any, I extends Input = {}> = (c: Context<E, P, I>, next: Next) => Promise<Response | void>;
21
21
  export declare type H<E extends Env = any, P extends string = any, I extends Input = {}, E2 extends Env = E, R extends HandlerResponse<any> = any> = Handler<E2, P, I, R> | MiddlewareHandler<E2, P, I>;
22
22
  export declare type NotFoundHandler<E extends Env = any> = (c: Context<E>) => Response | Promise<Response>;
23
23
  export declare type ErrorHandler<E extends Env = any> = (err: Error, c: Context<E>) => Response | Promise<Response>;
@@ -67,7 +67,7 @@ export interface HandlerInterface<E extends Env = Env, M extends string = any, S
67
67
  }
68
68
  export interface MiddlewareHandlerInterface<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> {
69
69
  (...handlers: MiddlewareHandler<E, MergePath<BasePath, ExtractKey<S>>>[]): Hono<E, S, BasePath>;
70
- <P extends string>(path: P, ...handlers: MiddlewareHandler<E, MergePath<BasePath, P>>[]): Hono<E, S, BasePath>;
70
+ <P extends string, E2 extends Env = E>(path: P, ...handlers: MiddlewareHandler<E2, MergePath<BasePath, P>>[]): Hono<E, S, BasePath>;
71
71
  }
72
72
  export interface OnHandlerInterface<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> {
73
73
  <M extends string, P extends string, R extends HandlerResponse<any> = any, I extends Input = {}, E2 extends Env = E, E3 extends Env = E>(method: M, path: P, ...handlers: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",