hono 2.5.4 → 2.5.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.
@@ -30,7 +30,7 @@ class Context {
30
30
  this._prettySpace = 2;
31
31
  this._executionCtx = executionCtx;
32
32
  this.req = req;
33
- this.env = env || {};
33
+ this.env = env;
34
34
  this.notFoundHandler = notFoundHandler;
35
35
  this.finalized = false;
36
36
  }
@@ -97,7 +97,7 @@ class Context {
97
97
  }
98
98
  newResponse(data, status, headers = {}) {
99
99
  return new Response(data, {
100
- status: status || this._status || 200,
100
+ status,
101
101
  headers: this._finalizeHeaders(headers)
102
102
  });
103
103
  }
@@ -133,16 +133,16 @@ class Context {
133
133
  }
134
134
  text(text, status = this._status, headers = {}) {
135
135
  headers["content-type"] = "text/plain; charset=UTF-8";
136
- return this.body(text, status, headers);
136
+ return this.newResponse(text, status, headers);
137
137
  }
138
138
  json(object, status = this._status, headers = {}) {
139
139
  const body = this._pretty ? JSON.stringify(object, null, this._prettySpace) : JSON.stringify(object);
140
140
  headers["content-type"] = "application/json; charset=UTF-8";
141
- return this.body(body, status, headers);
141
+ return this.newResponse(body, status, headers);
142
142
  }
143
143
  html(html, status = this._status, headers = {}) {
144
144
  headers["content-type"] = "text/html; charset=UTF-8";
145
- return this.body(html, status, headers);
145
+ return this.newResponse(html, status, headers);
146
146
  }
147
147
  redirect(location, status = 302) {
148
148
  return this.newResponse(null, status, {
@@ -27,7 +27,7 @@ __export(module_exports, {
27
27
  serveStatic: () => module2
28
28
  });
29
29
  module.exports = __toCommonJS(module_exports);
30
- var import_STATIC_CONTENT_MANIFEST = __toESM(require("__STATIC_CONTENT_MANIFEST"));
30
+ var import_STATIC_CONTENT_MANIFEST = __toESM(require("__STATIC_CONTENT_MANIFEST"), 1);
31
31
  var import_serve_static = require("./serve-static");
32
32
  const module2 = (options = { root: "" }) => {
33
33
  return (0, import_serve_static.serveStatic)({
@@ -45,9 +45,9 @@ function extendRequestPrototype() {
45
45
  Request.prototype.header = function(name) {
46
46
  if (!this.headerData) {
47
47
  this.headerData = {};
48
- for (const [key, value] of this.headers) {
48
+ this.headers.forEach((value, key) => {
49
49
  this.headerData[key] = value;
50
- }
50
+ });
51
51
  }
52
52
  if (name) {
53
53
  return this.headerData[name.toLowerCase()];
@@ -26,10 +26,10 @@ async function parseBody(r) {
26
26
  const contentType = r.headers.get("Content-Type");
27
27
  if (contentType && (contentType.startsWith("multipart/form-data") || contentType === "application/x-www-form-urlencoded")) {
28
28
  const form = {};
29
- body = [...await r.formData()].reduce((acc, cur) => {
30
- acc[cur[0]] = cur[1];
31
- return acc;
32
- }, form);
29
+ (await r.formData()).forEach((value, key) => {
30
+ form[key] = value;
31
+ });
32
+ body = form;
33
33
  }
34
34
  return body;
35
35
  }
@@ -46,9 +46,9 @@ const getContentFromKVAsset = async (path, options) => {
46
46
  if (!key) {
47
47
  return null;
48
48
  }
49
- let content = await ASSET_NAMESPACE.get(key, { type: "arrayBuffer" });
50
- if (content) {
51
- content = content;
49
+ const content = await ASSET_NAMESPACE.get(key, { type: "arrayBuffer" });
50
+ if (!content) {
51
+ return null;
52
52
  }
53
53
  return content;
54
54
  };
@@ -27,7 +27,7 @@ __export(jwt_exports, {
27
27
  Jwt: () => Jwt
28
28
  });
29
29
  module.exports = __toCommonJS(jwt_exports);
30
- var Jwt = __toESM(require("./jwt"));
30
+ var Jwt = __toESM(require("./jwt"), 1);
31
31
  // Annotate the CommonJS export names for ESM import in node:
32
32
  0 && (module.exports = {
33
33
  Jwt
package/dist/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /// <reference types="@cloudflare/workers-types" />
1
+ import type { ExecutionContext } from './types';
2
2
  import type { Environment, NotFoundHandler, ContextVariableMap } from './types';
3
3
  import type { CookieOptions } from './utils/cookie';
4
4
  import type { StatusCode } from './utils/http-status';
@@ -7,11 +7,11 @@ declare type Headers = Record<string, string | string[]>;
7
7
  declare type Runtime = 'node' | 'deno' | 'bun' | 'cloudflare' | 'fastly' | 'vercel' | 'other';
8
8
  export declare type Data = string | ArrayBuffer | ReadableStream;
9
9
  export declare class Context<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> {
10
- req: Request<P, S extends Schema ? SchemaToProp<S> : S>;
10
+ req: Request<unknown, P, S extends Schema ? SchemaToProp<S> : S>;
11
11
  env: E['Bindings'];
12
12
  finalized: boolean;
13
13
  error: Error | undefined;
14
- _status: StatusCode;
14
+ private _status;
15
15
  private _executionCtx;
16
16
  private _pretty;
17
17
  private _prettySpace;
@@ -19,7 +19,7 @@ export declare class Context<P extends string = string, E extends Partial<Enviro
19
19
  private _headers;
20
20
  private _res;
21
21
  private notFoundHandler;
22
- constructor(req: Request<P>, env?: E['Bindings'], executionCtx?: FetchEvent | ExecutionContext | undefined, notFoundHandler?: NotFoundHandler<E>);
22
+ constructor(req: Request<unknown, P>, env?: E['Bindings'], executionCtx?: FetchEvent | ExecutionContext | undefined, notFoundHandler?: NotFoundHandler<E>);
23
23
  get event(): FetchEvent;
24
24
  get executionCtx(): ExecutionContext;
25
25
  get res(): Response;
package/dist/context.js CHANGED
@@ -8,7 +8,7 @@ var Context = class {
8
8
  this._prettySpace = 2;
9
9
  this._executionCtx = executionCtx;
10
10
  this.req = req;
11
- this.env = env || {};
11
+ this.env = env;
12
12
  this.notFoundHandler = notFoundHandler;
13
13
  this.finalized = false;
14
14
  }
@@ -75,7 +75,7 @@ var Context = class {
75
75
  }
76
76
  newResponse(data, status, headers = {}) {
77
77
  return new Response(data, {
78
- status: status || this._status || 200,
78
+ status,
79
79
  headers: this._finalizeHeaders(headers)
80
80
  });
81
81
  }
@@ -111,16 +111,16 @@ var Context = class {
111
111
  }
112
112
  text(text, status = this._status, headers = {}) {
113
113
  headers["content-type"] = "text/plain; charset=UTF-8";
114
- return this.body(text, status, headers);
114
+ return this.newResponse(text, status, headers);
115
115
  }
116
116
  json(object, status = this._status, headers = {}) {
117
117
  const body = this._pretty ? JSON.stringify(object, null, this._prettySpace) : JSON.stringify(object);
118
118
  headers["content-type"] = "application/json; charset=UTF-8";
119
- return this.body(body, status, headers);
119
+ return this.newResponse(body, status, headers);
120
120
  }
121
121
  html(html, status = this._status, headers = {}) {
122
122
  headers["content-type"] = "text/html; charset=UTF-8";
123
- return this.body(html, status, headers);
123
+ return this.newResponse(html, status, headers);
124
124
  }
125
125
  redirect(location, status = 302) {
126
126
  return this.newResponse(null, status, {
package/dist/hono.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- /// <reference types="@cloudflare/workers-types" />
2
1
  import type { Router } from './router';
2
+ import type { ExecutionContext } from './types';
3
3
  import type { Handler, Environment, ParamKeys, ErrorHandler, NotFoundHandler } from './types';
4
4
  import type { Schema } from './validator/schema';
5
5
  interface HandlerInterface<P extends string, E extends Partial<Environment>, S extends Partial<Schema>, U = Hono<E, P, S>> {
@@ -1,4 +1,4 @@
1
- /// <reference types="@cloudflare/workers-types" />
1
+ import type { KVNamespace } from '@cloudflare/workers-types';
2
2
  import type { MiddlewareHandler } from '../../types';
3
3
  export declare type ServeStaticOptions = {
4
4
  root?: string;
package/dist/request.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { BodyData } from './utils/body';
2
2
  import type { Cookie } from './utils/cookie';
3
3
  declare type ValidatedData = Record<string, any>;
4
4
  declare global {
5
- interface Request<ParamKeyType extends string = string, Data extends ValidatedData = ValidatedData> {
5
+ interface Request<CfHostMetadata = unknown, ParamKeyType extends string = string, Data extends ValidatedData = ValidatedData> {
6
6
  paramData?: Record<ParamKeyType, string>;
7
7
  param: {
8
8
  (key: ParamKeyType): string;
package/dist/request.js CHANGED
@@ -23,9 +23,9 @@ function extendRequestPrototype() {
23
23
  Request.prototype.header = function(name) {
24
24
  if (!this.headerData) {
25
25
  this.headerData = {};
26
- for (const [key, value] of this.headers) {
26
+ this.headers.forEach((value, key) => {
27
27
  this.headerData[key] = value;
28
- }
28
+ });
29
29
  }
30
30
  if (name) {
31
31
  return this.headerData[name.toLowerCase()];
package/dist/types.d.ts CHANGED
@@ -19,4 +19,8 @@ export declare type ParamKeys<Path> = Path extends `${infer Component}/${infer R
19
19
  export interface CustomHandler<P extends string | Partial<Environment> | Schema = string, E = Partial<Environment> | Partial<Schema>, S = Partial<Schema>> {
20
20
  (c: Context<P extends string ? P : P extends Partial<Environment> ? string : P extends Partial<Schema> ? string : never, P extends Partial<Environment> ? P : P extends Partial<Schema> ? Partial<Environment> : E extends Partial<Environment> ? E extends Partial<Schema> ? Environment : E : E extends Partial<Schema> ? Partial<Environment> : Environment, S extends Schema ? S : P extends Schema ? P : E extends Schema ? E : any>, next: Next): Response | Promise<Response | undefined | void>;
21
21
  }
22
+ export interface ExecutionContext {
23
+ waitUntil(promise: Promise<any>): void;
24
+ passThroughOnException(): void;
25
+ }
22
26
  export {};
@@ -4,10 +4,10 @@ async function parseBody(r) {
4
4
  const contentType = r.headers.get("Content-Type");
5
5
  if (contentType && (contentType.startsWith("multipart/form-data") || contentType === "application/x-www-form-urlencoded")) {
6
6
  const form = {};
7
- body = [...await r.formData()].reduce((acc, cur) => {
8
- acc[cur[0]] = cur[1];
9
- return acc;
10
- }, form);
7
+ (await r.formData()).forEach((value, key) => {
8
+ form[key] = value;
9
+ });
10
+ body = form;
11
11
  }
12
12
  return body;
13
13
  }
@@ -1,4 +1,4 @@
1
- /// <reference types="@cloudflare/workers-types" />
1
+ import type { KVNamespace } from '@cloudflare/workers-types';
2
2
  export declare type KVAssetOptions = {
3
3
  manifest?: object | string;
4
4
  namespace?: KVNamespace;
@@ -24,9 +24,9 @@ var getContentFromKVAsset = async (path, options) => {
24
24
  if (!key) {
25
25
  return null;
26
26
  }
27
- let content = await ASSET_NAMESPACE.get(key, { type: "arrayBuffer" });
28
- if (content) {
29
- content = content;
27
+ const content = await ASSET_NAMESPACE.get(key, { type: "arrayBuffer" });
28
+ if (!content) {
29
+ return null;
30
30
  }
31
31
  return content;
32
32
  };
@@ -72,7 +72,7 @@ export declare abstract class VBase {
72
72
  asNumber: () => VNumber | VNumberArray;
73
73
  asBoolean: () => VBoolean | VBooleanArray;
74
74
  get(value: string): this;
75
- validate: <R extends Request<string, {
75
+ validate: <R extends Request<unknown, string, {
76
76
  [x: string]: any;
77
77
  }>>(req: R) => Promise<ValidateResult[]>;
78
78
  protected getTypeRuleName(): string;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "2.5.4",
4
- "description": "Ultrafast web framework for Cloudflare Workers.",
3
+ "version": "2.5.6",
4
+ "description": "Ultrafast web framework for Cloudflare Workers, Deno, and Bun.",
5
5
  "main": "dist/cjs/index.js",
6
+ "type": "module",
6
7
  "module": "dist/index.js",
7
8
  "types": "dist/index.d.ts",
8
9
  "files": [
@@ -249,7 +250,7 @@
249
250
  "bun"
250
251
  ],
251
252
  "devDependencies": {
252
- "@cloudflare/workers-types": "^3.16.0",
253
+ "@cloudflare/workers-types": "^4.20221111.1",
253
254
  "@types/crypto-js": "^4.1.1",
254
255
  "@types/glob": "^8.0.0",
255
256
  "@types/jest": "^29.0.2",