hono 2.0.7 → 2.0.8
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/compose.d.ts +5 -1
- package/dist/compose.js +2 -1
- package/dist/context.js +7 -7
- package/dist/hono.d.ts +1 -1
- package/dist/middleware/compress/index.d.ts +1 -1
- package/dist/middleware/cors/index.d.ts +1 -1
- package/dist/middleware/etag/index.js +1 -3
- package/dist/utils/buffer.d.ts +1 -1
- package/dist/utils/cloudflare.d.ts +1 -1
- package/dist/utils/crypto.d.ts +1 -1
- package/dist/utils/crypto.js +9 -0
- package/dist/utils/mime.js +1 -1
- package/package.json +1 -1
package/dist/compose.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { ErrorHandler, NotFoundHandler } from './hono';
|
|
2
|
-
export declare const compose: <C>(middleware: Function[], onError?: ErrorHandler
|
|
2
|
+
export declare const compose: <C>(middleware: Function[], onError?: ErrorHandler<{
|
|
3
|
+
[x: string]: any;
|
|
4
|
+
}> | undefined, onNotFound?: NotFoundHandler<{
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
}> | undefined) => (context: C, next?: Function | undefined) => Promise<C>;
|
package/dist/compose.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.compose = void 0;
|
|
|
4
4
|
const context_1 = require("./context");
|
|
5
5
|
// Based on the code in the MIT licensed `koa-compose` package.
|
|
6
6
|
const compose = (middleware, onError, onNotFound) => {
|
|
7
|
+
const middlewareLength = middleware.length;
|
|
7
8
|
return (context, next) => {
|
|
8
9
|
let index = -1;
|
|
9
10
|
return dispatch(0);
|
|
@@ -13,7 +14,7 @@ const compose = (middleware, onError, onNotFound) => {
|
|
|
13
14
|
}
|
|
14
15
|
let handler = middleware[i];
|
|
15
16
|
index = i;
|
|
16
|
-
if (i ===
|
|
17
|
+
if (i === middlewareLength && next)
|
|
17
18
|
handler = next;
|
|
18
19
|
if (!handler) {
|
|
19
20
|
if (context instanceof context_1.HonoContext && context.finalized === false && onNotFound) {
|
package/dist/context.js
CHANGED
|
@@ -39,7 +39,7 @@ class HonoContext {
|
|
|
39
39
|
}
|
|
40
40
|
header(name, value) {
|
|
41
41
|
this._headers || (this._headers = {});
|
|
42
|
-
this._headers[name] = value;
|
|
42
|
+
this._headers[name.toLowerCase()] = value;
|
|
43
43
|
if (this.finalized) {
|
|
44
44
|
this.res.headers.set(name, value);
|
|
45
45
|
}
|
|
@@ -62,7 +62,7 @@ class HonoContext {
|
|
|
62
62
|
this._prettySpace = space;
|
|
63
63
|
}
|
|
64
64
|
newResponse(data, status, headers = {}) {
|
|
65
|
-
const _headers = { ...this._headers
|
|
65
|
+
const _headers = { ...this._headers };
|
|
66
66
|
if (this._res) {
|
|
67
67
|
this._res.headers.forEach((v, k) => {
|
|
68
68
|
_headers[k] = v;
|
|
@@ -70,25 +70,25 @@ class HonoContext {
|
|
|
70
70
|
}
|
|
71
71
|
return new Response(data, {
|
|
72
72
|
status: status || this._status || 200,
|
|
73
|
-
headers: _headers,
|
|
73
|
+
headers: { ..._headers, ...headers },
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
body(data, status = this._status, headers = {}) {
|
|
77
77
|
return this.newResponse(data, status, headers);
|
|
78
78
|
}
|
|
79
79
|
text(text, status = this._status, headers = {}) {
|
|
80
|
-
headers['
|
|
80
|
+
headers['content-type'] = 'text/plain; charset=UTF-8';
|
|
81
81
|
return this.body(text, status, headers);
|
|
82
82
|
}
|
|
83
83
|
json(object, status = this._status, headers = {}) {
|
|
84
84
|
const body = this._pretty
|
|
85
85
|
? JSON.stringify(object, null, this._prettySpace)
|
|
86
86
|
: JSON.stringify(object);
|
|
87
|
-
headers['
|
|
87
|
+
headers['content-type'] = 'application/json; charset=UTF-8';
|
|
88
88
|
return this.body(body, status, headers);
|
|
89
89
|
}
|
|
90
90
|
html(html, status = this._status, headers = {}) {
|
|
91
|
-
headers['
|
|
91
|
+
headers['content-type'] = 'text/html; charset=UTF-8';
|
|
92
92
|
return this.body(html, status, headers);
|
|
93
93
|
}
|
|
94
94
|
redirect(location, status = 302) {
|
|
@@ -103,7 +103,7 @@ class HonoContext {
|
|
|
103
103
|
}
|
|
104
104
|
cookie(name, value, opt) {
|
|
105
105
|
const cookie = (0, cookie_1.serialize)(name, value, opt);
|
|
106
|
-
this.header('
|
|
106
|
+
this.header('set-cookie', cookie);
|
|
107
107
|
}
|
|
108
108
|
notFound() {
|
|
109
109
|
return this.notFoundHandler(this);
|
package/dist/hono.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export declare class Hono<E extends Env = Env, P extends string = '/'> extends H
|
|
|
50
50
|
private matchRoute;
|
|
51
51
|
private dispatch;
|
|
52
52
|
handleEvent(event: FetchEvent): Promise<Response>;
|
|
53
|
-
fetch: (request: Request, env?: E, executionCtx?: ExecutionContext) => Promise<Response>;
|
|
53
|
+
fetch: (request: Request, env?: E | undefined, executionCtx?: ExecutionContext | undefined) => Promise<Response>;
|
|
54
54
|
request(input: RequestInfo, requestInit?: RequestInit): Promise<Response>;
|
|
55
55
|
}
|
|
56
56
|
export {};
|
|
@@ -4,5 +4,5 @@ declare type EncodingType = 'gzip' | 'deflate';
|
|
|
4
4
|
interface CompressionOptions {
|
|
5
5
|
encoding?: EncodingType;
|
|
6
6
|
}
|
|
7
|
-
export declare const compress: (options?: CompressionOptions) => (ctx: Context, next: Next) => Promise<void>;
|
|
7
|
+
export declare const compress: (options?: CompressionOptions | undefined) => (ctx: Context, next: Next) => Promise<void>;
|
|
8
8
|
export {};
|
|
@@ -8,5 +8,5 @@ declare type CORSOptions = {
|
|
|
8
8
|
credentials?: boolean;
|
|
9
9
|
exposeHeaders?: string[];
|
|
10
10
|
};
|
|
11
|
-
export declare const cors: (options?: CORSOptions) => (c: Context, next: Next) => Promise<void>;
|
|
11
|
+
export declare const cors: (options?: CORSOptions | undefined) => (c: Context, next: Next) => Promise<void>;
|
|
12
12
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.etag = void 0;
|
|
4
|
-
const body_1 = require("../../utils/body");
|
|
5
4
|
const crypto_1 = require("../../utils/crypto");
|
|
6
5
|
const etag = (options = { weak: false }) => {
|
|
7
6
|
return async (c, next) => {
|
|
@@ -9,8 +8,7 @@ const etag = (options = { weak: false }) => {
|
|
|
9
8
|
await next();
|
|
10
9
|
const res = c.res;
|
|
11
10
|
const clone = res.clone();
|
|
12
|
-
const
|
|
13
|
-
const hash = await (0, crypto_1.sha1)(body);
|
|
11
|
+
const hash = await (0, crypto_1.sha1)(res.body || '');
|
|
14
12
|
const etag = options.weak ? `W/"${hash}"` : `"${hash}"`;
|
|
15
13
|
if (ifNoneMatch && ifNoneMatch === etag) {
|
|
16
14
|
await clone.blob(); // Force using body
|
package/dist/utils/buffer.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const equal: (a: ArrayBuffer, b: ArrayBuffer) => boolean;
|
|
2
|
-
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function) => Promise<boolean>;
|
|
2
|
+
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function | undefined) => Promise<boolean>;
|
|
3
3
|
export declare const bufferToString: (buffer: ArrayBuffer) => string;
|
|
@@ -3,4 +3,4 @@ export declare type KVAssetOptions = {
|
|
|
3
3
|
manifest?: object | string;
|
|
4
4
|
namespace?: KVNamespace;
|
|
5
5
|
};
|
|
6
|
-
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions) => Promise<ArrayBuffer | null>;
|
|
6
|
+
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions | undefined) => Promise<ArrayBuffer | null>;
|
package/dist/utils/crypto.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ declare type Algorithm = {
|
|
|
2
2
|
name: string;
|
|
3
3
|
alias: string;
|
|
4
4
|
};
|
|
5
|
-
declare type Data = string | boolean | number | object | ArrayBufferView | ArrayBuffer;
|
|
5
|
+
declare type Data = string | boolean | number | object | ArrayBufferView | ArrayBuffer | ReadableStream;
|
|
6
6
|
export declare const sha256: (data: Data) => Promise<string | null>;
|
|
7
7
|
export declare const sha1: (data: Data) => Promise<string | null>;
|
|
8
8
|
export declare const md5: (data: Data) => Promise<string | null>;
|
package/dist/utils/crypto.js
CHANGED
|
@@ -21,6 +21,15 @@ const md5 = async (data) => {
|
|
|
21
21
|
exports.md5 = md5;
|
|
22
22
|
const createHash = async (data, algorithm) => {
|
|
23
23
|
let sourceBuffer;
|
|
24
|
+
if (data instanceof ReadableStream) {
|
|
25
|
+
let body = '';
|
|
26
|
+
const reader = data.getReader();
|
|
27
|
+
await reader?.read().then(async (chuck) => {
|
|
28
|
+
const value = await (0, exports.createHash)(chuck.value || '', algorithm);
|
|
29
|
+
body += value;
|
|
30
|
+
});
|
|
31
|
+
return body;
|
|
32
|
+
}
|
|
24
33
|
if (ArrayBuffer.isView(data) || data instanceof ArrayBuffer) {
|
|
25
34
|
sourceBuffer = data;
|
|
26
35
|
}
|
package/dist/utils/mime.js
CHANGED