hono 3.6.3 → 3.7.0-rc.2
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/client/client.js +12 -1
- package/dist/cjs/context.js +16 -1
- package/dist/cjs/helper/cookie/index.js +1 -1
- package/dist/cjs/helper/testing/index.js +34 -0
- package/dist/cjs/middleware/jwt/index.js +11 -2
- package/dist/cjs/utils/body.js +12 -1
- package/dist/cjs/utils/cookie.js +6 -3
- package/dist/cjs/utils/jwt/jwt.js +3 -3
- package/dist/cjs/utils/stream.js +62 -0
- package/dist/client/client.js +12 -1
- package/dist/context.js +16 -1
- package/dist/helper/cookie/index.js +1 -1
- package/dist/helper/testing/index.js +11 -0
- package/dist/middleware/jwt/index.js +7 -1
- package/dist/types/client/types.d.ts +8 -4
- package/dist/types/context.d.ts +3 -0
- package/dist/types/helper/testing/index.d.ts +4 -0
- package/dist/types/middleware/jwt/index.d.ts +6 -0
- package/dist/types/utils/body.d.ts +1 -1
- package/dist/types/utils/cookie.d.ts +1 -0
- package/dist/types/utils/jwt/jwt.d.ts +5 -3
- package/dist/types/utils/stream.d.ts +11 -0
- package/dist/utils/body.js +12 -1
- package/dist/utils/cookie.js +6 -3
- package/dist/utils/jwt/jwt.js +4 -4
- package/dist/utils/stream.js +39 -0
- package/package.json +9 -1
|
@@ -21,6 +21,7 @@ __export(client_exports, {
|
|
|
21
21
|
hc: () => hc
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(client_exports);
|
|
24
|
+
var import_cookie = require("../utils/cookie");
|
|
24
25
|
var import_utils = require("./utils");
|
|
25
26
|
const createProxy = (callback, path) => {
|
|
26
27
|
const proxy = new Proxy(() => {
|
|
@@ -86,7 +87,17 @@ class ClientRequestImpl {
|
|
|
86
87
|
}
|
|
87
88
|
let methodUpperCase = this.method.toUpperCase();
|
|
88
89
|
let setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
89
|
-
const headerValues =
|
|
90
|
+
const headerValues = {
|
|
91
|
+
...args?.header ?? {},
|
|
92
|
+
...opt?.headers ? opt.headers : {}
|
|
93
|
+
};
|
|
94
|
+
if (args?.cookie) {
|
|
95
|
+
const cookies = [];
|
|
96
|
+
for (const [key, value] of Object.entries(args.cookie)) {
|
|
97
|
+
cookies.push((0, import_cookie.serialize)(key, value, { path: "/" }));
|
|
98
|
+
}
|
|
99
|
+
headerValues["Cookie"] = cookies.join(",");
|
|
100
|
+
}
|
|
90
101
|
if (this.cType)
|
|
91
102
|
headerValues["Content-Type"] = this.cType;
|
|
92
103
|
const headers = new Headers(headerValues ?? void 0);
|
package/dist/cjs/context.js
CHANGED
|
@@ -23,6 +23,8 @@ __export(context_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(context_exports);
|
|
24
24
|
var import_types = require("./types");
|
|
25
25
|
var import_cookie = require("./utils/cookie");
|
|
26
|
+
var import_stream = require("./utils/stream");
|
|
27
|
+
const TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
26
28
|
class Context {
|
|
27
29
|
constructor(req, options) {
|
|
28
30
|
this.env = {};
|
|
@@ -139,7 +141,7 @@ class Context {
|
|
|
139
141
|
this._pH = {};
|
|
140
142
|
}
|
|
141
143
|
if (this._pH["content-type"]) {
|
|
142
|
-
this._pH["content-type"] =
|
|
144
|
+
this._pH["content-type"] = TEXT_PLAIN;
|
|
143
145
|
}
|
|
144
146
|
return typeof arg === "number" ? this.newResponse(text, arg, headers) : this.newResponse(text, arg);
|
|
145
147
|
};
|
|
@@ -168,6 +170,19 @@ class Context {
|
|
|
168
170
|
this._h.set("Location", location);
|
|
169
171
|
return this.newResponse(null, status);
|
|
170
172
|
};
|
|
173
|
+
this.streamText = (cb, arg, headers) => {
|
|
174
|
+
headers ?? (headers = {});
|
|
175
|
+
this.header("content-type", TEXT_PLAIN);
|
|
176
|
+
this.header("x-content-type-options", "nosniff");
|
|
177
|
+
this.header("transfer-encoding", "chunked");
|
|
178
|
+
return this.stream(cb, arg, headers);
|
|
179
|
+
};
|
|
180
|
+
this.stream = (cb, arg, headers) => {
|
|
181
|
+
const { readable, writable } = new TransformStream();
|
|
182
|
+
const stream = new import_stream.StreamingApi(writable);
|
|
183
|
+
cb(stream).finally(() => stream.close());
|
|
184
|
+
return typeof arg === "number" ? this.newResponse(readable, arg, headers) : this.newResponse(readable, arg);
|
|
185
|
+
};
|
|
171
186
|
this.cookie = (name, value, opt) => {
|
|
172
187
|
const cookie = (0, import_cookie.serialize)(name, value, opt);
|
|
173
188
|
this.header("set-cookie", cookie, { append: true });
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var testing_exports = {};
|
|
20
|
+
__export(testing_exports, {
|
|
21
|
+
testClient: () => testClient
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(testing_exports);
|
|
24
|
+
var import_client = require("../../client");
|
|
25
|
+
const testClient = (app, Env, executionCtx) => {
|
|
26
|
+
const customFetch = (input, init) => {
|
|
27
|
+
return app.request(input, init, Env, executionCtx);
|
|
28
|
+
};
|
|
29
|
+
return (0, import_client.hc)("", { fetch: customFetch });
|
|
30
|
+
};
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
testClient
|
|
34
|
+
});
|
|
@@ -18,7 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var jwt_exports = {};
|
|
20
20
|
__export(jwt_exports, {
|
|
21
|
-
|
|
21
|
+
decode: () => decode,
|
|
22
|
+
jwt: () => jwt,
|
|
23
|
+
sign: () => sign,
|
|
24
|
+
verify: () => verify
|
|
22
25
|
});
|
|
23
26
|
module.exports = __toCommonJS(jwt_exports);
|
|
24
27
|
var import_http_exception = require("../../http-exception");
|
|
@@ -80,7 +83,13 @@ const jwt = (options) => {
|
|
|
80
83
|
await next();
|
|
81
84
|
};
|
|
82
85
|
};
|
|
86
|
+
const verify = import_jwt.Jwt.verify;
|
|
87
|
+
const decode = import_jwt.Jwt.decode;
|
|
88
|
+
const sign = import_jwt.Jwt.sign;
|
|
83
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
84
90
|
0 && (module.exports = {
|
|
85
|
-
|
|
91
|
+
decode,
|
|
92
|
+
jwt,
|
|
93
|
+
sign,
|
|
94
|
+
verify
|
|
86
95
|
});
|
package/dist/cjs/utils/body.js
CHANGED
|
@@ -29,7 +29,18 @@ const parseBody = async (request) => {
|
|
|
29
29
|
if (formData) {
|
|
30
30
|
const form = {};
|
|
31
31
|
formData.forEach((value, key) => {
|
|
32
|
-
|
|
32
|
+
if (key.slice(-2) === "[]") {
|
|
33
|
+
if (!form[key]) {
|
|
34
|
+
form[key] = [value.toString()];
|
|
35
|
+
} else {
|
|
36
|
+
if (Array.isArray(form[key])) {
|
|
37
|
+
;
|
|
38
|
+
form[key].push(value.toString());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
form[key] = value;
|
|
43
|
+
}
|
|
33
44
|
});
|
|
34
45
|
body = form;
|
|
35
46
|
}
|
package/dist/cjs/utils/cookie.js
CHANGED
|
@@ -88,13 +88,13 @@ const _serialize = (name, value, opt = {}) => {
|
|
|
88
88
|
cookie += `; Max-Age=${Math.floor(opt.maxAge)}`;
|
|
89
89
|
}
|
|
90
90
|
if (opt.domain) {
|
|
91
|
-
cookie +=
|
|
91
|
+
cookie += `; Domain=${opt.domain}`;
|
|
92
92
|
}
|
|
93
93
|
if (opt.path) {
|
|
94
|
-
cookie +=
|
|
94
|
+
cookie += `; Path=${opt.path}`;
|
|
95
95
|
}
|
|
96
96
|
if (opt.expires) {
|
|
97
|
-
cookie +=
|
|
97
|
+
cookie += `; Expires=${opt.expires.toUTCString()}`;
|
|
98
98
|
}
|
|
99
99
|
if (opt.httpOnly) {
|
|
100
100
|
cookie += "; HttpOnly";
|
|
@@ -105,6 +105,9 @@ const _serialize = (name, value, opt = {}) => {
|
|
|
105
105
|
if (opt.sameSite) {
|
|
106
106
|
cookie += `; SameSite=${opt.sameSite}`;
|
|
107
107
|
}
|
|
108
|
+
if (opt.partitioned) {
|
|
109
|
+
cookie += "; Partitioned";
|
|
110
|
+
}
|
|
108
111
|
return cookie;
|
|
109
112
|
};
|
|
110
113
|
const serialize = (name, value, opt = {}) => {
|
|
@@ -76,7 +76,7 @@ const param = (name) => {
|
|
|
76
76
|
throw new import_types2.JwtAlgorithmNotImplemented(name);
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
-
const signing = async (data, secret, alg =
|
|
79
|
+
const signing = async (data, secret, alg = "HS256") => {
|
|
80
80
|
if (!crypto.subtle || !crypto.subtle.importKey) {
|
|
81
81
|
throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");
|
|
82
82
|
}
|
|
@@ -90,7 +90,7 @@ const signing = async (data, secret, alg = import_types.AlgorithmTypes.HS256) =>
|
|
|
90
90
|
);
|
|
91
91
|
return await crypto.subtle.sign(param(alg), cryptoKey, utf8Encoder2.encode(data));
|
|
92
92
|
};
|
|
93
|
-
const sign = async (payload, secret, alg =
|
|
93
|
+
const sign = async (payload, secret, alg = "HS256") => {
|
|
94
94
|
const encodedPayload = encodeJwtPart(payload);
|
|
95
95
|
const encodedHeader = encodeJwtPart({ alg, typ: "JWT" });
|
|
96
96
|
const partialToken = `${encodedHeader}.${encodedPayload}`;
|
|
@@ -98,7 +98,7 @@ const sign = async (payload, secret, alg = import_types.AlgorithmTypes.HS256) =>
|
|
|
98
98
|
const signature = encodeSignaturePart(signaturePart);
|
|
99
99
|
return `${partialToken}.${signature}`;
|
|
100
100
|
};
|
|
101
|
-
const verify = async (token, secret, alg =
|
|
101
|
+
const verify = async (token, secret, alg = "HS256") => {
|
|
102
102
|
const tokenParts = token.split(".");
|
|
103
103
|
if (tokenParts.length !== 3) {
|
|
104
104
|
throw new import_types2.JwtTokenInvalid(token);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var stream_exports = {};
|
|
20
|
+
__export(stream_exports, {
|
|
21
|
+
StreamingApi: () => StreamingApi
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(stream_exports);
|
|
24
|
+
class StreamingApi {
|
|
25
|
+
constructor(writable) {
|
|
26
|
+
this.writable = writable;
|
|
27
|
+
this.writer = writable.getWriter();
|
|
28
|
+
this.encoder = new TextEncoder();
|
|
29
|
+
}
|
|
30
|
+
async write(input) {
|
|
31
|
+
try {
|
|
32
|
+
if (typeof input === "string") {
|
|
33
|
+
input = this.encoder.encode(input);
|
|
34
|
+
}
|
|
35
|
+
await this.writer.write(input);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
}
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
async writeln(input) {
|
|
41
|
+
await this.write(input + "\n");
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
sleep(ms) {
|
|
45
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
46
|
+
}
|
|
47
|
+
async close() {
|
|
48
|
+
try {
|
|
49
|
+
await this.writer.close();
|
|
50
|
+
} catch (e) {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async pipe(body) {
|
|
54
|
+
this.writer.releaseLock();
|
|
55
|
+
await body.pipeTo(this.writable, { preventClose: true });
|
|
56
|
+
this.writer = this.writable.getWriter();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
StreamingApi
|
|
62
|
+
});
|
package/dist/client/client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/client/client.ts
|
|
2
|
+
import { serialize } from "../utils/cookie.js";
|
|
2
3
|
import { deepMerge, mergePath, removeIndexString, replaceUrlParam } from "./utils.js";
|
|
3
4
|
var createProxy = (callback, path) => {
|
|
4
5
|
const proxy = new Proxy(() => {
|
|
@@ -64,7 +65,17 @@ var ClientRequestImpl = class {
|
|
|
64
65
|
}
|
|
65
66
|
let methodUpperCase = this.method.toUpperCase();
|
|
66
67
|
let setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
67
|
-
const headerValues =
|
|
68
|
+
const headerValues = {
|
|
69
|
+
...args?.header ?? {},
|
|
70
|
+
...opt?.headers ? opt.headers : {}
|
|
71
|
+
};
|
|
72
|
+
if (args?.cookie) {
|
|
73
|
+
const cookies = [];
|
|
74
|
+
for (const [key, value] of Object.entries(args.cookie)) {
|
|
75
|
+
cookies.push(serialize(key, value, { path: "/" }));
|
|
76
|
+
}
|
|
77
|
+
headerValues["Cookie"] = cookies.join(",");
|
|
78
|
+
}
|
|
68
79
|
if (this.cType)
|
|
69
80
|
headerValues["Content-Type"] = this.cType;
|
|
70
81
|
const headers = new Headers(headerValues ?? void 0);
|
package/dist/context.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/context.ts
|
|
2
2
|
import { FetchEventLike } from "./types.js";
|
|
3
3
|
import { serialize } from "./utils/cookie.js";
|
|
4
|
+
import { StreamingApi } from "./utils/stream.js";
|
|
5
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
4
6
|
var Context = class {
|
|
5
7
|
constructor(req, options) {
|
|
6
8
|
this.env = {};
|
|
@@ -117,7 +119,7 @@ var Context = class {
|
|
|
117
119
|
this._pH = {};
|
|
118
120
|
}
|
|
119
121
|
if (this._pH["content-type"]) {
|
|
120
|
-
this._pH["content-type"] =
|
|
122
|
+
this._pH["content-type"] = TEXT_PLAIN;
|
|
121
123
|
}
|
|
122
124
|
return typeof arg === "number" ? this.newResponse(text, arg, headers) : this.newResponse(text, arg);
|
|
123
125
|
};
|
|
@@ -146,6 +148,19 @@ var Context = class {
|
|
|
146
148
|
this._h.set("Location", location);
|
|
147
149
|
return this.newResponse(null, status);
|
|
148
150
|
};
|
|
151
|
+
this.streamText = (cb, arg, headers) => {
|
|
152
|
+
headers ?? (headers = {});
|
|
153
|
+
this.header("content-type", TEXT_PLAIN);
|
|
154
|
+
this.header("x-content-type-options", "nosniff");
|
|
155
|
+
this.header("transfer-encoding", "chunked");
|
|
156
|
+
return this.stream(cb, arg, headers);
|
|
157
|
+
};
|
|
158
|
+
this.stream = (cb, arg, headers) => {
|
|
159
|
+
const { readable, writable } = new TransformStream();
|
|
160
|
+
const stream = new StreamingApi(writable);
|
|
161
|
+
cb(stream).finally(() => stream.close());
|
|
162
|
+
return typeof arg === "number" ? this.newResponse(readable, arg, headers) : this.newResponse(readable, arg);
|
|
163
|
+
};
|
|
149
164
|
this.cookie = (name, value, opt) => {
|
|
150
165
|
const cookie = serialize(name, value, opt);
|
|
151
166
|
this.header("set-cookie", cookie, { append: true });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/helper/testing/index.ts
|
|
2
|
+
import { hc } from "../../client/index.js";
|
|
3
|
+
var testClient = (app, Env, executionCtx) => {
|
|
4
|
+
const customFetch = (input, init) => {
|
|
5
|
+
return app.request(input, init, Env, executionCtx);
|
|
6
|
+
};
|
|
7
|
+
return hc("", { fetch: customFetch });
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
testClient
|
|
11
|
+
};
|
|
@@ -2,15 +2,18 @@ import type { Hono } from '../hono';
|
|
|
2
2
|
import type { Schema } from '../types';
|
|
3
3
|
import type { RemoveBlankRecord } from '../utils/types';
|
|
4
4
|
declare type HonoRequest = typeof Hono.prototype['request'];
|
|
5
|
-
export declare type ClientRequestOptions = {
|
|
5
|
+
export declare type ClientRequestOptions<T = unknown> = keyof T extends never ? {
|
|
6
6
|
headers?: Record<string, string>;
|
|
7
7
|
fetch?: typeof fetch | HonoRequest;
|
|
8
|
+
} : {
|
|
9
|
+
headers: T;
|
|
10
|
+
fetch?: typeof fetch | HonoRequest;
|
|
8
11
|
};
|
|
9
12
|
declare type ClientRequest<S extends Schema> = {
|
|
10
13
|
[M in keyof S]: S[M] extends {
|
|
11
14
|
input: infer R;
|
|
12
15
|
output: infer O;
|
|
13
|
-
} ? RemoveBlankRecord<R> extends never ? (args?: {}, options?: ClientRequestOptions) => Promise<ClientResponse<O>> : (args:
|
|
16
|
+
} ? RemoveBlankRecord<R> extends never ? (args?: {}, options?: ClientRequestOptions) => Promise<ClientResponse<O>> : (args: R, options?: ClientRequestOptions) => Promise<ClientResponse<O>> : never;
|
|
14
17
|
} & {
|
|
15
18
|
$url: () => URL;
|
|
16
19
|
};
|
|
@@ -32,8 +35,9 @@ export interface ClientResponse<T> {
|
|
|
32
35
|
export interface Response extends ClientResponse<unknown> {
|
|
33
36
|
}
|
|
34
37
|
export declare type Fetch<T> = (args?: InferRequestType<T>, opt?: ClientRequestOptions) => Promise<ClientResponse<InferResponseType<T>>>;
|
|
35
|
-
export declare type InferResponseType<T> = T extends (args: any | undefined) => Promise<ClientResponse<infer O>> ? O : never;
|
|
36
|
-
export declare type InferRequestType<T> = T extends (args: infer R) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
38
|
+
export declare type InferResponseType<T> = T extends (args: any | undefined, options: any | undefined) => Promise<ClientResponse<infer O>> ? O : never;
|
|
39
|
+
export declare type InferRequestType<T> = T extends (args: infer R, options: any | undefined) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
40
|
+
export declare type InferRequestOptionsType<T> = T extends (args: any, options: infer R) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
37
41
|
declare type PathToChain<Path extends string, E extends Schema, Original extends string = ''> = Path extends `/${infer P}` ? PathToChain<P, E, Path> : Path extends `${infer P}/${infer R}` ? {
|
|
38
42
|
[K in P]: PathToChain<R, E, Original>;
|
|
39
43
|
} : {
|
package/dist/types/context.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { FetchEventLike } from './types';
|
|
|
3
3
|
import type { Env, NotFoundHandler, Input, TypedResponse } from './types';
|
|
4
4
|
import type { CookieOptions } from './utils/cookie';
|
|
5
5
|
import type { StatusCode } from './utils/http-status';
|
|
6
|
+
import { StreamingApi } from './utils/stream';
|
|
6
7
|
import type { JSONValue, InterfaceToType } from './utils/types';
|
|
7
8
|
declare type Runtime = 'node' | 'deno' | 'bun' | 'workerd' | 'fastly' | 'edge-light' | 'lagon' | 'other';
|
|
8
9
|
declare type HeaderRecord = Record<string, string | string[]>;
|
|
@@ -99,6 +100,8 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
99
100
|
jsonT: JSONTRespond;
|
|
100
101
|
html: HTMLRespond;
|
|
101
102
|
redirect: (location: string, status?: StatusCode) => Response;
|
|
103
|
+
streamText: (cb: (stream: StreamingApi) => Promise<void>, arg?: StatusCode | ResponseInit, headers?: HeaderRecord) => Response;
|
|
104
|
+
stream: (cb: (stream: StreamingApi) => Promise<void>, arg?: StatusCode | ResponseInit, headers?: HeaderRecord) => Response;
|
|
102
105
|
/** @deprecated
|
|
103
106
|
* Use Cookie Middleware instead of `c.cookie()`. The `c.cookie()` will be removed in v4.
|
|
104
107
|
*
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Hono } from '../../hono';
|
|
2
|
+
declare type ExtractEnv<T> = T extends Hono<infer E, any, any> ? E : never;
|
|
3
|
+
export declare const testClient: <T extends Hono<any, any, any>>(app: T, Env?: {} | ExtractEnv<T>["Bindings"] | undefined, executionCtx?: any) => import("../../utils/types").UnionToIntersection<import("../../client/types").Client<T>>;
|
|
4
|
+
export {};
|
|
@@ -10,3 +10,9 @@ export declare const jwt: (options: {
|
|
|
10
10
|
cookie?: string;
|
|
11
11
|
alg?: string;
|
|
12
12
|
}) => MiddlewareHandler;
|
|
13
|
+
export declare const verify: (token: string, secret: string, alg?: "HS256" | "HS384" | "HS512") => Promise<any>;
|
|
14
|
+
export declare const decode: (token: string) => {
|
|
15
|
+
header: any;
|
|
16
|
+
payload: any;
|
|
17
|
+
};
|
|
18
|
+
export declare const sign: (payload: unknown, secret: string, alg?: "HS256" | "HS384" | "HS512") => Promise<string>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { HonoRequest } from '../request';
|
|
2
|
-
export declare type BodyData = Record<string, string | File>;
|
|
2
|
+
export declare type BodyData = Record<string, string | string[] | File>;
|
|
3
3
|
export declare const parseBody: <T extends BodyData = BodyData>(request: HonoRequest | Request) => Promise<T>;
|
|
@@ -9,6 +9,7 @@ export declare type CookieOptions = {
|
|
|
9
9
|
secure?: boolean;
|
|
10
10
|
signingSecret?: string;
|
|
11
11
|
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
12
|
+
partitioned?: boolean;
|
|
12
13
|
};
|
|
13
14
|
export declare const parse: (cookie: string, name?: string) => Cookie;
|
|
14
15
|
export declare const parseSigned: (cookie: string, secret: string | BufferSource, name?: string) => Promise<SignedCookie>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { AlgorithmTypes } from './types';
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
1
|
+
import type { AlgorithmTypes } from './types';
|
|
2
|
+
declare type AlgorithmTypeName = keyof typeof AlgorithmTypes;
|
|
3
|
+
export declare const sign: (payload: unknown, secret: string, alg?: AlgorithmTypeName) => Promise<string>;
|
|
4
|
+
export declare const verify: (token: string, secret: string, alg?: AlgorithmTypeName) => Promise<any>;
|
|
4
5
|
export declare const decode: (token: string) => {
|
|
5
6
|
header: any;
|
|
6
7
|
payload: any;
|
|
7
8
|
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class StreamingApi {
|
|
2
|
+
private writer;
|
|
3
|
+
private encoder;
|
|
4
|
+
private writable;
|
|
5
|
+
constructor(writable: WritableStream);
|
|
6
|
+
write(input: Uint8Array | string): Promise<this>;
|
|
7
|
+
writeln(input: string): Promise<this>;
|
|
8
|
+
sleep(ms: number): Promise<unknown>;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
pipe(body: ReadableStream): Promise<void>;
|
|
11
|
+
}
|
package/dist/utils/body.js
CHANGED
|
@@ -7,7 +7,18 @@ var parseBody = async (request) => {
|
|
|
7
7
|
if (formData) {
|
|
8
8
|
const form = {};
|
|
9
9
|
formData.forEach((value, key) => {
|
|
10
|
-
|
|
10
|
+
if (key.slice(-2) === "[]") {
|
|
11
|
+
if (!form[key]) {
|
|
12
|
+
form[key] = [value.toString()];
|
|
13
|
+
} else {
|
|
14
|
+
if (Array.isArray(form[key])) {
|
|
15
|
+
;
|
|
16
|
+
form[key].push(value.toString());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
form[key] = value;
|
|
21
|
+
}
|
|
11
22
|
});
|
|
12
23
|
body = form;
|
|
13
24
|
}
|
package/dist/utils/cookie.js
CHANGED
|
@@ -63,13 +63,13 @@ var _serialize = (name, value, opt = {}) => {
|
|
|
63
63
|
cookie += `; Max-Age=${Math.floor(opt.maxAge)}`;
|
|
64
64
|
}
|
|
65
65
|
if (opt.domain) {
|
|
66
|
-
cookie +=
|
|
66
|
+
cookie += `; Domain=${opt.domain}`;
|
|
67
67
|
}
|
|
68
68
|
if (opt.path) {
|
|
69
|
-
cookie +=
|
|
69
|
+
cookie += `; Path=${opt.path}`;
|
|
70
70
|
}
|
|
71
71
|
if (opt.expires) {
|
|
72
|
-
cookie +=
|
|
72
|
+
cookie += `; Expires=${opt.expires.toUTCString()}`;
|
|
73
73
|
}
|
|
74
74
|
if (opt.httpOnly) {
|
|
75
75
|
cookie += "; HttpOnly";
|
|
@@ -80,6 +80,9 @@ var _serialize = (name, value, opt = {}) => {
|
|
|
80
80
|
if (opt.sameSite) {
|
|
81
81
|
cookie += `; SameSite=${opt.sameSite}`;
|
|
82
82
|
}
|
|
83
|
+
if (opt.partitioned) {
|
|
84
|
+
cookie += "; Partitioned";
|
|
85
|
+
}
|
|
83
86
|
return cookie;
|
|
84
87
|
};
|
|
85
88
|
var serialize = (name, value, opt = {}) => {
|
package/dist/utils/jwt/jwt.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/utils/jwt/jwt.ts
|
|
2
2
|
import { encodeBase64Url, decodeBase64Url } from "../../utils/encode.js";
|
|
3
|
-
import {
|
|
3
|
+
import { JwtTokenIssuedAt } from "./types.js";
|
|
4
4
|
import {
|
|
5
5
|
JwtTokenInvalid,
|
|
6
6
|
JwtTokenNotBefore,
|
|
@@ -40,7 +40,7 @@ var param = (name) => {
|
|
|
40
40
|
throw new JwtAlgorithmNotImplemented(name);
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
var signing = async (data, secret, alg =
|
|
43
|
+
var signing = async (data, secret, alg = "HS256") => {
|
|
44
44
|
if (!crypto.subtle || !crypto.subtle.importKey) {
|
|
45
45
|
throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");
|
|
46
46
|
}
|
|
@@ -54,7 +54,7 @@ var signing = async (data, secret, alg = AlgorithmTypes.HS256) => {
|
|
|
54
54
|
);
|
|
55
55
|
return await crypto.subtle.sign(param(alg), cryptoKey, utf8Encoder2.encode(data));
|
|
56
56
|
};
|
|
57
|
-
var sign = async (payload, secret, alg =
|
|
57
|
+
var sign = async (payload, secret, alg = "HS256") => {
|
|
58
58
|
const encodedPayload = encodeJwtPart(payload);
|
|
59
59
|
const encodedHeader = encodeJwtPart({ alg, typ: "JWT" });
|
|
60
60
|
const partialToken = `${encodedHeader}.${encodedPayload}`;
|
|
@@ -62,7 +62,7 @@ var sign = async (payload, secret, alg = AlgorithmTypes.HS256) => {
|
|
|
62
62
|
const signature = encodeSignaturePart(signaturePart);
|
|
63
63
|
return `${partialToken}.${signature}`;
|
|
64
64
|
};
|
|
65
|
-
var verify = async (token, secret, alg =
|
|
65
|
+
var verify = async (token, secret, alg = "HS256") => {
|
|
66
66
|
const tokenParts = token.split(".");
|
|
67
67
|
if (tokenParts.length !== 3) {
|
|
68
68
|
throw new JwtTokenInvalid(token);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/utils/stream.ts
|
|
2
|
+
var StreamingApi = class {
|
|
3
|
+
constructor(writable) {
|
|
4
|
+
this.writable = writable;
|
|
5
|
+
this.writer = writable.getWriter();
|
|
6
|
+
this.encoder = new TextEncoder();
|
|
7
|
+
}
|
|
8
|
+
async write(input) {
|
|
9
|
+
try {
|
|
10
|
+
if (typeof input === "string") {
|
|
11
|
+
input = this.encoder.encode(input);
|
|
12
|
+
}
|
|
13
|
+
await this.writer.write(input);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
}
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
async writeln(input) {
|
|
19
|
+
await this.write(input + "\n");
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
sleep(ms) {
|
|
23
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
24
|
+
}
|
|
25
|
+
async close() {
|
|
26
|
+
try {
|
|
27
|
+
await this.writer.close();
|
|
28
|
+
} catch (e) {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async pipe(body) {
|
|
32
|
+
this.writer.releaseLock();
|
|
33
|
+
await body.pipeTo(this.writable, { preventClose: true });
|
|
34
|
+
this.writer = this.writable.getWriter();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
StreamingApi
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0-rc.2",
|
|
4
4
|
"description": "Ultrafast web framework for the Edges",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -233,6 +233,11 @@
|
|
|
233
233
|
"types": "./dist/types/adapter/lambda-edge/index.d.ts",
|
|
234
234
|
"import": "./dist/adapter/lambda-edge/index.js",
|
|
235
235
|
"require": "./dist/cjs/adapter/lambda-edge/index.js"
|
|
236
|
+
},
|
|
237
|
+
"./testing": {
|
|
238
|
+
"types": "./dist/types/helper/testing/index.d.ts",
|
|
239
|
+
"import": "./dist/helper/testing/index.js",
|
|
240
|
+
"require": "./dist/cjs/helper/testing/index.js"
|
|
236
241
|
}
|
|
237
242
|
},
|
|
238
243
|
"typesVersions": {
|
|
@@ -353,6 +358,9 @@
|
|
|
353
358
|
],
|
|
354
359
|
"lambda-edge": [
|
|
355
360
|
"./dist/types/adapter/lambda-edge"
|
|
361
|
+
],
|
|
362
|
+
"testing": [
|
|
363
|
+
"./dist/types/helper/testing"
|
|
356
364
|
]
|
|
357
365
|
}
|
|
358
366
|
},
|