hono 2.5.3 → 2.5.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.
- package/dist/cjs/context.js +5 -5
- package/dist/cjs/request.js +2 -2
- package/dist/cjs/utils/body.js +4 -4
- package/dist/cjs/utils/cloudflare.js +3 -3
- package/dist/context.d.ts +4 -4
- package/dist/context.js +5 -5
- package/dist/hono.d.ts +1 -1
- package/dist/middleware/serve-static/serve-static.d.ts +1 -1
- package/dist/request.d.ts +1 -1
- package/dist/request.js +2 -2
- package/dist/types.d.ts +4 -0
- package/dist/utils/body.js +4 -4
- package/dist/utils/cloudflare.d.ts +1 -1
- package/dist/utils/cloudflare.js +3 -3
- package/dist/validator/validator.d.ts +1 -1
- package/package.json +79 -3
package/dist/cjs/context.js
CHANGED
|
@@ -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
|
|
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.
|
|
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.
|
|
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.
|
|
145
|
+
return this.newResponse(html, status, headers);
|
|
146
146
|
}
|
|
147
147
|
redirect(location, status = 302) {
|
|
148
148
|
return this.newResponse(null, status, {
|
package/dist/cjs/request.js
CHANGED
|
@@ -45,9 +45,9 @@ function extendRequestPrototype() {
|
|
|
45
45
|
Request.prototype.header = function(name) {
|
|
46
46
|
if (!this.headerData) {
|
|
47
47
|
this.headerData = {};
|
|
48
|
-
|
|
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()];
|
package/dist/cjs/utils/body.js
CHANGED
|
@@ -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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
50
|
-
if (content) {
|
|
51
|
-
|
|
49
|
+
const content = await ASSET_NAMESPACE.get(key, { type: "arrayBuffer" });
|
|
50
|
+
if (!content) {
|
|
51
|
+
return null;
|
|
52
52
|
}
|
|
53
53
|
return content;
|
|
54
54
|
};
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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>> {
|
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
|
-
|
|
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 {};
|
package/dist/utils/body.js
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
(await r.formData()).forEach((value, key) => {
|
|
8
|
+
form[key] = value;
|
|
9
|
+
});
|
|
10
|
+
body = form;
|
|
11
11
|
}
|
|
12
12
|
return body;
|
|
13
13
|
}
|
package/dist/utils/cloudflare.js
CHANGED
|
@@ -24,9 +24,9 @@ var getContentFromKVAsset = async (path, options) => {
|
|
|
24
24
|
if (!key) {
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
if (content) {
|
|
29
|
-
|
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "2.5.
|
|
4
|
-
"description": "Ultrafast web framework for Cloudflare Workers.",
|
|
3
|
+
"version": "2.5.5",
|
|
4
|
+
"description": "Ultrafast web framework for Cloudflare Workers, Deno, and Bun.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -147,6 +147,82 @@
|
|
|
147
147
|
"require": "./dist/cjs/utils/*.js"
|
|
148
148
|
}
|
|
149
149
|
},
|
|
150
|
+
"typesVersions": {
|
|
151
|
+
"*": {
|
|
152
|
+
"basic-auth": [
|
|
153
|
+
"./dist/middleware/basic-auth"
|
|
154
|
+
],
|
|
155
|
+
"bearer-auth": [
|
|
156
|
+
"./dist/middleware/bearer-auth"
|
|
157
|
+
],
|
|
158
|
+
"cache": [
|
|
159
|
+
"./dist/middleware/cache"
|
|
160
|
+
],
|
|
161
|
+
"compress": [
|
|
162
|
+
"./dist/middleware/compress"
|
|
163
|
+
],
|
|
164
|
+
"cors": [
|
|
165
|
+
"./dist/middleware/cors"
|
|
166
|
+
],
|
|
167
|
+
"etag": [
|
|
168
|
+
"./dist/middleware/etag"
|
|
169
|
+
],
|
|
170
|
+
"html": [
|
|
171
|
+
"./dist/middleware/html"
|
|
172
|
+
],
|
|
173
|
+
"jsx": [
|
|
174
|
+
"./dist/middleware/jsx"
|
|
175
|
+
],
|
|
176
|
+
"jsx/jsx-runtime": [
|
|
177
|
+
"./dist/middleware/jsx/jsx-runtime.d.ts"
|
|
178
|
+
],
|
|
179
|
+
"jsx/jsx-dev-runtime": [
|
|
180
|
+
"./dist/middleware/jsx/jsx-dev-runtime.d.ts"
|
|
181
|
+
],
|
|
182
|
+
"jwt": [
|
|
183
|
+
"./dist/middleware/jwt"
|
|
184
|
+
],
|
|
185
|
+
"logger": [
|
|
186
|
+
"./dist/middleware/logger"
|
|
187
|
+
],
|
|
188
|
+
"powered-by": [
|
|
189
|
+
"./dist/middleware/powered-by"
|
|
190
|
+
],
|
|
191
|
+
"pretty-json": [
|
|
192
|
+
"./dist/middleware/pretty-json"
|
|
193
|
+
],
|
|
194
|
+
"serve-static": [
|
|
195
|
+
"./dist/middleware/serve-static/index.d.ts"
|
|
196
|
+
],
|
|
197
|
+
"serve-static.bun": [
|
|
198
|
+
"./dist/middleware/serve-static/bun.d.ts"
|
|
199
|
+
],
|
|
200
|
+
"serve-static.module": [
|
|
201
|
+
"./dist/middleware/serve-static/module.d.ts"
|
|
202
|
+
],
|
|
203
|
+
"validator": [
|
|
204
|
+
"./dist/middleware/validator"
|
|
205
|
+
],
|
|
206
|
+
"router/reg-exp-router": [
|
|
207
|
+
"./dist/router/reg-exp-router/router.d.ts"
|
|
208
|
+
],
|
|
209
|
+
"router/smart-router": [
|
|
210
|
+
"./dist/router/smart-router/router.d.ts"
|
|
211
|
+
],
|
|
212
|
+
"router/static-router": [
|
|
213
|
+
"./dist/router/static-router/router.d.ts"
|
|
214
|
+
],
|
|
215
|
+
"router/trie-router": [
|
|
216
|
+
"./dist/router/trie-router/router.d.ts"
|
|
217
|
+
],
|
|
218
|
+
"utils/jwt": [
|
|
219
|
+
"./dist/utils/jwt/index.d.ts"
|
|
220
|
+
],
|
|
221
|
+
"utils/*": [
|
|
222
|
+
"./dist/utils/*"
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
},
|
|
150
226
|
"author": "Yusuke Wada <yusuke@kamawada.com> (https://github.com/yusukebe)",
|
|
151
227
|
"license": "MIT",
|
|
152
228
|
"repository": {
|
|
@@ -173,7 +249,7 @@
|
|
|
173
249
|
"bun"
|
|
174
250
|
],
|
|
175
251
|
"devDependencies": {
|
|
176
|
-
"@cloudflare/workers-types": "^
|
|
252
|
+
"@cloudflare/workers-types": "^4.20221111.1",
|
|
177
253
|
"@types/crypto-js": "^4.1.1",
|
|
178
254
|
"@types/glob": "^8.0.0",
|
|
179
255
|
"@types/jest": "^29.0.2",
|