hono 3.7.4 → 3.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.
- package/dist/cjs/context.js +2 -1
- package/dist/cjs/hono-base.js +2 -2
- package/dist/cjs/test-utils/setup-vitest.js +41 -0
- package/dist/cjs/types.js +4 -0
- package/dist/cjs/validator/validator.js +27 -11
- package/dist/context.js +1 -0
- package/dist/hono-base.js +2 -2
- package/dist/test-utils/setup-vitest.js +23 -0
- package/dist/types/adapter/vercel/handler.d.ts +1 -0
- package/dist/types/context.d.ts +1 -2
- package/dist/types/hono-base.d.ts +1 -1
- package/dist/types/test-utils/setup-vitest.d.ts +1 -0
- package/dist/types/types.d.ts +2 -0
- package/dist/types.js +3 -0
- package/dist/validator/validator.js +27 -11
- package/package.json +1 -2
package/dist/cjs/context.js
CHANGED
|
@@ -21,6 +21,7 @@ __export(context_exports, {
|
|
|
21
21
|
Context: () => Context
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(context_exports);
|
|
24
|
+
var import_types = require("./types");
|
|
24
25
|
var import_cookie = require("./utils/cookie");
|
|
25
26
|
var import_stream = require("./utils/stream");
|
|
26
27
|
const TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
@@ -199,7 +200,7 @@ class Context {
|
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
get event() {
|
|
202
|
-
if (this._exCtx instanceof FetchEvent) {
|
|
203
|
+
if (this._exCtx instanceof import_types.FetchEvent) {
|
|
203
204
|
return this._exCtx;
|
|
204
205
|
} else {
|
|
205
206
|
throw Error("This context has no FetchEvent");
|
package/dist/cjs/hono-base.js
CHANGED
|
@@ -230,12 +230,12 @@ class Hono extends defineDynamicClass() {
|
|
|
230
230
|
} catch (err) {
|
|
231
231
|
return this.handleError(err, c);
|
|
232
232
|
}
|
|
233
|
-
if (res
|
|
233
|
+
if (res instanceof Response)
|
|
234
234
|
return res;
|
|
235
235
|
if ("response" in res) {
|
|
236
236
|
res = res.response;
|
|
237
237
|
}
|
|
238
|
-
if (res
|
|
238
|
+
if (res instanceof Response)
|
|
239
239
|
return res;
|
|
240
240
|
return (async () => {
|
|
241
241
|
let awaited;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
|
+
mod
|
|
19
|
+
));
|
|
20
|
+
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
21
|
+
var import_vitest = require("vitest");
|
|
22
|
+
import_vitest.vi.stubGlobal("crypto", import_node_crypto.default);
|
|
23
|
+
class MockCache {
|
|
24
|
+
constructor(name, store) {
|
|
25
|
+
this.name = name;
|
|
26
|
+
this.store = store;
|
|
27
|
+
}
|
|
28
|
+
async match(key) {
|
|
29
|
+
return this.store.get(key) || null;
|
|
30
|
+
}
|
|
31
|
+
async put(key, response) {
|
|
32
|
+
this.store.set(key, response);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const globalStore = /* @__PURE__ */ new Map();
|
|
36
|
+
const caches = {
|
|
37
|
+
open: (name) => {
|
|
38
|
+
return new MockCache(name, globalStore);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
import_vitest.vi.stubGlobal("caches", caches);
|
package/dist/cjs/types.js
CHANGED
|
@@ -18,12 +18,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var types_exports = {};
|
|
20
20
|
__export(types_exports, {
|
|
21
|
+
FetchEvent: () => FetchEvent,
|
|
21
22
|
FetchEventLike: () => FetchEventLike
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(types_exports);
|
|
24
25
|
class FetchEventLike {
|
|
25
26
|
}
|
|
27
|
+
class FetchEvent extends FetchEventLike {
|
|
28
|
+
}
|
|
26
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
30
|
0 && (module.exports = {
|
|
31
|
+
FetchEvent,
|
|
28
32
|
FetchEventLike
|
|
29
33
|
});
|
|
@@ -29,6 +29,10 @@ const validator = (target, validationFunc) => {
|
|
|
29
29
|
switch (target) {
|
|
30
30
|
case "json":
|
|
31
31
|
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
|
+
}
|
|
32
36
|
const arrayBuffer = c.req.bodyCache.arrayBuffer ?? await c.req.raw.arrayBuffer();
|
|
33
37
|
value = await new Response(arrayBuffer).json();
|
|
34
38
|
c.req.bodyCache.json = value;
|
|
@@ -45,17 +49,29 @@ const validator = (target, validationFunc) => {
|
|
|
45
49
|
}
|
|
46
50
|
break;
|
|
47
51
|
case "form": {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
try {
|
|
53
|
+
const contentType = c.req.header("Content-Type");
|
|
54
|
+
if (contentType) {
|
|
55
|
+
const arrayBuffer = c.req.bodyCache.arrayBuffer ?? await c.req.raw.arrayBuffer();
|
|
56
|
+
const formData = await (0, import_buffer.bufferToFormData)(arrayBuffer, contentType);
|
|
57
|
+
const form = {};
|
|
58
|
+
formData.forEach((value2, key) => {
|
|
59
|
+
form[key] = value2;
|
|
60
|
+
});
|
|
61
|
+
value = form;
|
|
62
|
+
c.req.bodyCache.formData = formData;
|
|
63
|
+
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
64
|
+
}
|
|
65
|
+
} catch (e) {
|
|
66
|
+
let message = "Malformed FormData request.";
|
|
67
|
+
message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
|
|
68
|
+
return c.json(
|
|
69
|
+
{
|
|
70
|
+
success: false,
|
|
71
|
+
message
|
|
72
|
+
},
|
|
73
|
+
400
|
|
74
|
+
);
|
|
59
75
|
}
|
|
60
76
|
break;
|
|
61
77
|
}
|
package/dist/context.js
CHANGED
package/dist/hono-base.js
CHANGED
|
@@ -208,12 +208,12 @@ var Hono = class extends defineDynamicClass() {
|
|
|
208
208
|
} catch (err) {
|
|
209
209
|
return this.handleError(err, c);
|
|
210
210
|
}
|
|
211
|
-
if (res
|
|
211
|
+
if (res instanceof Response)
|
|
212
212
|
return res;
|
|
213
213
|
if ("response" in res) {
|
|
214
214
|
res = res.response;
|
|
215
215
|
}
|
|
216
|
-
if (res
|
|
216
|
+
if (res instanceof Response)
|
|
217
217
|
return res;
|
|
218
218
|
return (async () => {
|
|
219
219
|
let awaited;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/test-utils/setup-vitest.ts
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import { vi } from "vitest";
|
|
4
|
+
vi.stubGlobal("crypto", crypto);
|
|
5
|
+
var MockCache = class {
|
|
6
|
+
constructor(name, store) {
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.store = store;
|
|
9
|
+
}
|
|
10
|
+
async match(key) {
|
|
11
|
+
return this.store.get(key) || null;
|
|
12
|
+
}
|
|
13
|
+
async put(key, response) {
|
|
14
|
+
this.store.set(key, response);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var globalStore = /* @__PURE__ */ new Map();
|
|
18
|
+
var caches = {
|
|
19
|
+
open: (name) => {
|
|
20
|
+
return new MockCache(name, globalStore);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
vi.stubGlobal("caches", caches);
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference lib="es2022" />
|
|
2
|
-
/// <reference lib="webworker" />
|
|
3
1
|
import type { HonoRequest } from './request';
|
|
4
2
|
import type { Env, NotFoundHandler, Input, TypedResponse } from './types';
|
|
3
|
+
import { FetchEvent } from './types';
|
|
5
4
|
import type { CookieOptions } from './utils/cookie';
|
|
6
5
|
import type { StatusCode } from './utils/http-status';
|
|
7
6
|
import { StreamingApi } from './utils/stream';
|
|
@@ -10,11 +10,11 @@ interface RouterRoute {
|
|
|
10
10
|
}
|
|
11
11
|
declare const Hono_base: new <E_1 extends Env = Env, S_1 extends Schema = {}, BasePath_1 extends string = "/">() => {
|
|
12
12
|
all: HandlerInterface<E_1, "all", S_1, BasePath_1>;
|
|
13
|
+
options: HandlerInterface<E_1, "options", S_1, BasePath_1>;
|
|
13
14
|
get: HandlerInterface<E_1, "get", S_1, BasePath_1>;
|
|
14
15
|
post: HandlerInterface<E_1, "post", S_1, BasePath_1>;
|
|
15
16
|
put: HandlerInterface<E_1, "put", S_1, BasePath_1>;
|
|
16
17
|
delete: HandlerInterface<E_1, "delete", S_1, BasePath_1>;
|
|
17
|
-
options: HandlerInterface<E_1, "options", S_1, BasePath_1>;
|
|
18
18
|
patch: HandlerInterface<E_1, "patch", S_1, BasePath_1>;
|
|
19
19
|
} & {
|
|
20
20
|
on: OnHandlerInterface<E_1, S_1, BasePath_1>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/types.d.ts
CHANGED
package/dist/types.js
CHANGED
|
@@ -7,6 +7,10 @@ var validator = (target, validationFunc) => {
|
|
|
7
7
|
switch (target) {
|
|
8
8
|
case "json":
|
|
9
9
|
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
|
+
}
|
|
10
14
|
const arrayBuffer = c.req.bodyCache.arrayBuffer ?? await c.req.raw.arrayBuffer();
|
|
11
15
|
value = await new Response(arrayBuffer).json();
|
|
12
16
|
c.req.bodyCache.json = value;
|
|
@@ -23,17 +27,29 @@ var validator = (target, validationFunc) => {
|
|
|
23
27
|
}
|
|
24
28
|
break;
|
|
25
29
|
case "form": {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
try {
|
|
31
|
+
const contentType = c.req.header("Content-Type");
|
|
32
|
+
if (contentType) {
|
|
33
|
+
const arrayBuffer = c.req.bodyCache.arrayBuffer ?? await c.req.raw.arrayBuffer();
|
|
34
|
+
const formData = await bufferToFormData(arrayBuffer, contentType);
|
|
35
|
+
const form = {};
|
|
36
|
+
formData.forEach((value2, key) => {
|
|
37
|
+
form[key] = value2;
|
|
38
|
+
});
|
|
39
|
+
value = form;
|
|
40
|
+
c.req.bodyCache.formData = formData;
|
|
41
|
+
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
42
|
+
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
let message = "Malformed FormData request.";
|
|
45
|
+
message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
|
|
46
|
+
return c.json(
|
|
47
|
+
{
|
|
48
|
+
success: false,
|
|
49
|
+
message
|
|
50
|
+
},
|
|
51
|
+
400
|
|
52
|
+
);
|
|
37
53
|
}
|
|
38
54
|
break;
|
|
39
55
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.6",
|
|
4
4
|
"description": "Ultrafast web framework for the Edges",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -431,7 +431,6 @@
|
|
|
431
431
|
"tsx": "^3.11.0",
|
|
432
432
|
"typescript": "^4.8.3",
|
|
433
433
|
"vitest": "^0.34.3",
|
|
434
|
-
"vitest-environment-miniflare": "^2.14.1",
|
|
435
434
|
"wrangler": "^2.12.0",
|
|
436
435
|
"zod": "^3.20.2"
|
|
437
436
|
},
|