@kerebron/extension-server-hono 0.4.8 → 0.4.10
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/esm/HonoYjsMemAdapter.d.ts +0 -1
- package/esm/HonoYjsMemAdapter.d.ts.map +1 -1
- package/esm/HonoYjsMemAdapter.js +31 -79
- package/esm/deps/jsr.io/@hono/hono/4.10.7/src/context.js +309 -412
- package/esm/deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.js +9 -42
- package/esm/deps/jsr.io/@hono/hono/4.10.7/src/hono-base.js +192 -299
- package/esm/deps/jsr.io/@hono/hono/4.10.7/src/http-exception.js +2 -12
- package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request.js +82 -125
- package/esm/mod.d.ts +0 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +1 -1
- package/package.json +1 -1
- package/esm/_dnt.polyfills.d.ts +0 -7
- package/esm/_dnt.polyfills.d.ts.map +0 -1
- package/esm/_dnt.polyfills.js +0 -1
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _HonoRequest_instances, _HonoRequest_validatedData, _HonoRequest_matchResult, _HonoRequest_getDecodedParam, _HonoRequest_getAllDecodedParams, _HonoRequest_getParamValue, _HonoRequest_cachedBody;
|
|
13
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
2
|
import { HTTPException } from './http-exception.js';
|
|
15
3
|
import { GET_MATCH_RESULT } from './request/constants.js';
|
|
@@ -17,97 +5,65 @@ import { parseBody } from './utils/body.js';
|
|
|
17
5
|
import { decodeURIComponent_, getQueryParam, getQueryParams, tryDecode } from './utils/url.js';
|
|
18
6
|
const tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
19
7
|
export class HonoRequest {
|
|
8
|
+
/**
|
|
9
|
+
* `.raw` can get the raw Request object.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // For Cloudflare Workers
|
|
16
|
+
* app.post('/', async (c) => {
|
|
17
|
+
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
18
|
+
* ...
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
raw;
|
|
23
|
+
#validatedData; // Short name of validatedData
|
|
24
|
+
#matchResult;
|
|
25
|
+
routeIndex = 0;
|
|
26
|
+
/**
|
|
27
|
+
* `.path` can get the pathname of the request.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://hono.dev/docs/api/request#path}
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* app.get('/about/me', (c) => {
|
|
34
|
+
* const pathname = c.req.path // `/about/me`
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
path;
|
|
39
|
+
bodyCache = {};
|
|
20
40
|
constructor(request, path = '/', matchResult = [[]]) {
|
|
21
|
-
_HonoRequest_instances.add(this);
|
|
22
|
-
/**
|
|
23
|
-
* `.raw` can get the raw Request object.
|
|
24
|
-
*
|
|
25
|
-
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* // For Cloudflare Workers
|
|
30
|
-
* app.post('/', async (c) => {
|
|
31
|
-
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
32
|
-
* ...
|
|
33
|
-
* })
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
Object.defineProperty(this, "raw", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: void 0
|
|
41
|
-
});
|
|
42
|
-
_HonoRequest_validatedData.set(this, void 0); // Short name of validatedData
|
|
43
|
-
_HonoRequest_matchResult.set(this, void 0);
|
|
44
|
-
Object.defineProperty(this, "routeIndex", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true,
|
|
48
|
-
value: 0
|
|
49
|
-
});
|
|
50
|
-
/**
|
|
51
|
-
* `.path` can get the pathname of the request.
|
|
52
|
-
*
|
|
53
|
-
* @see {@link https://hono.dev/docs/api/request#path}
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* app.get('/about/me', (c) => {
|
|
58
|
-
* const pathname = c.req.path // `/about/me`
|
|
59
|
-
* })
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
Object.defineProperty(this, "path", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: true,
|
|
65
|
-
writable: true,
|
|
66
|
-
value: void 0
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(this, "bodyCache", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
configurable: true,
|
|
71
|
-
writable: true,
|
|
72
|
-
value: {}
|
|
73
|
-
});
|
|
74
|
-
_HonoRequest_cachedBody.set(this, (key) => {
|
|
75
|
-
const { bodyCache, raw } = this;
|
|
76
|
-
const cachedBody = bodyCache[key];
|
|
77
|
-
if (cachedBody) {
|
|
78
|
-
return cachedBody;
|
|
79
|
-
}
|
|
80
|
-
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
81
|
-
if (anyCachedKey) {
|
|
82
|
-
return bodyCache[anyCachedKey].then((body) => {
|
|
83
|
-
if (anyCachedKey === 'json') {
|
|
84
|
-
body = JSON.stringify(body);
|
|
85
|
-
}
|
|
86
|
-
return new Response(body)[key]();
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
return (bodyCache[key] = raw[key]());
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* `.json()` can parse Request body of type `application/json`
|
|
93
|
-
*
|
|
94
|
-
* @see {@link https://hono.dev/docs/api/request#json}
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```ts
|
|
98
|
-
* app.post('/entry', async (c) => {
|
|
99
|
-
* const body = await c.req.json()
|
|
100
|
-
* })
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
);
|
|
104
41
|
this.raw = request;
|
|
105
42
|
this.path = path;
|
|
106
|
-
|
|
107
|
-
|
|
43
|
+
this.#matchResult = matchResult;
|
|
44
|
+
this.#validatedData = {};
|
|
108
45
|
}
|
|
109
46
|
param(key) {
|
|
110
|
-
return key ?
|
|
47
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
48
|
+
}
|
|
49
|
+
#getDecodedParam(key) {
|
|
50
|
+
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
51
|
+
const param = this.#getParamValue(paramKey);
|
|
52
|
+
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
53
|
+
}
|
|
54
|
+
#getAllDecodedParams() {
|
|
55
|
+
const decoded = {};
|
|
56
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
57
|
+
for (const key of keys) {
|
|
58
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
59
|
+
if (value !== undefined) {
|
|
60
|
+
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return decoded;
|
|
64
|
+
}
|
|
65
|
+
#getParamValue(paramKey) {
|
|
66
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
111
67
|
}
|
|
112
68
|
query(key) {
|
|
113
69
|
return getQueryParam(this.url, key);
|
|
@@ -128,6 +84,23 @@ export class HonoRequest {
|
|
|
128
84
|
async parseBody(options) {
|
|
129
85
|
return (this.bodyCache.parsedBody ??= await parseBody(this, options));
|
|
130
86
|
}
|
|
87
|
+
#cachedBody = (key) => {
|
|
88
|
+
const { bodyCache, raw } = this;
|
|
89
|
+
const cachedBody = bodyCache[key];
|
|
90
|
+
if (cachedBody) {
|
|
91
|
+
return cachedBody;
|
|
92
|
+
}
|
|
93
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
94
|
+
if (anyCachedKey) {
|
|
95
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
96
|
+
if (anyCachedKey === 'json') {
|
|
97
|
+
body = JSON.stringify(body);
|
|
98
|
+
}
|
|
99
|
+
return new Response(body)[key]();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return (bodyCache[key] = raw[key]());
|
|
103
|
+
};
|
|
131
104
|
/**
|
|
132
105
|
* `.json()` can parse Request body of type `application/json`
|
|
133
106
|
*
|
|
@@ -141,7 +114,7 @@ export class HonoRequest {
|
|
|
141
114
|
* ```
|
|
142
115
|
*/
|
|
143
116
|
json() {
|
|
144
|
-
return
|
|
117
|
+
return this.#cachedBody('text').then((text) => JSON.parse(text));
|
|
145
118
|
}
|
|
146
119
|
/**
|
|
147
120
|
* `.text()` can parse Request body of type `text/plain`
|
|
@@ -156,7 +129,7 @@ export class HonoRequest {
|
|
|
156
129
|
* ```
|
|
157
130
|
*/
|
|
158
131
|
text() {
|
|
159
|
-
return
|
|
132
|
+
return this.#cachedBody('text');
|
|
160
133
|
}
|
|
161
134
|
/**
|
|
162
135
|
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
@@ -171,7 +144,7 @@ export class HonoRequest {
|
|
|
171
144
|
* ```
|
|
172
145
|
*/
|
|
173
146
|
arrayBuffer() {
|
|
174
|
-
return
|
|
147
|
+
return this.#cachedBody('arrayBuffer');
|
|
175
148
|
}
|
|
176
149
|
/**
|
|
177
150
|
* Parses the request body as a `Blob`.
|
|
@@ -184,7 +157,7 @@ export class HonoRequest {
|
|
|
184
157
|
* @see https://hono.dev/docs/api/request#blob
|
|
185
158
|
*/
|
|
186
159
|
blob() {
|
|
187
|
-
return
|
|
160
|
+
return this.#cachedBody('blob');
|
|
188
161
|
}
|
|
189
162
|
/**
|
|
190
163
|
* Parses the request body as `FormData`.
|
|
@@ -197,7 +170,7 @@ export class HonoRequest {
|
|
|
197
170
|
* @see https://hono.dev/docs/api/request#formdata
|
|
198
171
|
*/
|
|
199
172
|
formData() {
|
|
200
|
-
return
|
|
173
|
+
return this.#cachedBody('formData');
|
|
201
174
|
}
|
|
202
175
|
/**
|
|
203
176
|
* Adds validated data to the request.
|
|
@@ -206,10 +179,10 @@ export class HonoRequest {
|
|
|
206
179
|
* @param data - The validated data to add.
|
|
207
180
|
*/
|
|
208
181
|
addValidatedData(target, data) {
|
|
209
|
-
|
|
182
|
+
this.#validatedData[target] = data;
|
|
210
183
|
}
|
|
211
184
|
valid(target) {
|
|
212
|
-
return
|
|
185
|
+
return this.#validatedData[target];
|
|
213
186
|
}
|
|
214
187
|
/**
|
|
215
188
|
* `.url()` can get the request url strings.
|
|
@@ -242,24 +215,8 @@ export class HonoRequest {
|
|
|
242
215
|
get method() {
|
|
243
216
|
return this.raw.method;
|
|
244
217
|
}
|
|
245
|
-
get [(
|
|
246
|
-
|
|
247
|
-
const param = __classPrivateFieldGet(this, _HonoRequest_instances, "m", _HonoRequest_getParamValue).call(this, paramKey);
|
|
248
|
-
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
249
|
-
}, _HonoRequest_getAllDecodedParams = function _HonoRequest_getAllDecodedParams() {
|
|
250
|
-
const decoded = {};
|
|
251
|
-
const keys = Object.keys(__classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[0][this.routeIndex][1]);
|
|
252
|
-
for (const key of keys) {
|
|
253
|
-
const value = __classPrivateFieldGet(this, _HonoRequest_instances, "m", _HonoRequest_getParamValue).call(this, __classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[0][this.routeIndex][1][key]);
|
|
254
|
-
if (value !== undefined) {
|
|
255
|
-
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return decoded;
|
|
259
|
-
}, _HonoRequest_getParamValue = function _HonoRequest_getParamValue(paramKey) {
|
|
260
|
-
return __classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[1] ? __classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[1][paramKey] : paramKey;
|
|
261
|
-
}, GET_MATCH_RESULT)]() {
|
|
262
|
-
return __classPrivateFieldGet(this, _HonoRequest_matchResult, "f");
|
|
218
|
+
get [GET_MATCH_RESULT]() {
|
|
219
|
+
return this.#matchResult;
|
|
263
220
|
}
|
|
264
221
|
/**
|
|
265
222
|
* `.matchedRoutes()` can return a matched route in the handler
|
|
@@ -289,7 +246,7 @@ export class HonoRequest {
|
|
|
289
246
|
* ```
|
|
290
247
|
*/
|
|
291
248
|
get matchedRoutes() {
|
|
292
|
-
return
|
|
249
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
293
250
|
}
|
|
294
251
|
/**
|
|
295
252
|
* `routePath()` can retrieve the path registered within the handler
|
|
@@ -308,7 +265,7 @@ export class HonoRequest {
|
|
|
308
265
|
* ```
|
|
309
266
|
*/
|
|
310
267
|
get routePath() {
|
|
311
|
-
return
|
|
268
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
312
269
|
}
|
|
313
270
|
}
|
|
314
271
|
/**
|
package/esm/mod.d.ts
CHANGED
package/esm/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,+DAA+D,CAAC;AAEzF,MAAM,WAAW,aAAa;IAC5B,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;CACzD"}
|
package/esm/mod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/package.json
CHANGED
package/esm/_dnt.polyfills.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
|
package/esm/_dnt.polyfills.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|