@kerebron/extension-server-hono 0.4.26 → 0.4.27

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.
Files changed (59) hide show
  1. package/package.json +2 -1
  2. package/esm/HonoYjsMemAdapter.d.ts +0 -41
  3. package/esm/HonoYjsMemAdapter.d.ts.map +0 -1
  4. package/esm/HonoYjsMemAdapter.js +0 -203
  5. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/compose.d.ts +0 -15
  6. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/compose.d.ts.map +0 -1
  7. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/compose.js +0 -64
  8. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/context.d.ts +0 -452
  9. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/context.d.ts.map +0 -1
  10. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/context.js +0 -410
  11. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/helper/websocket/index.d.ts +0 -70
  12. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/helper/websocket/index.d.ts.map +0 -1
  13. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/helper/websocket/index.js +0 -62
  14. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/hono-base.d.ts +0 -221
  15. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/hono-base.d.ts.map +0 -1
  16. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/hono-base.js +0 -391
  17. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/http-exception.d.ts +0 -60
  18. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/http-exception.d.ts.map +0 -1
  19. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/http-exception.js +0 -61
  20. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/request/constants.d.ts +0 -2
  21. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/request/constants.d.ts.map +0 -1
  22. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/request/constants.js +0 -1
  23. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/request.d.ts +0 -314
  24. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/request.d.ts.map +0 -1
  25. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/request.js +0 -327
  26. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/router.d.ts +0 -98
  27. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/router.d.ts.map +0 -1
  28. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/router.js +0 -25
  29. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/types.d.ts +0 -574
  30. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/types.d.ts.map +0 -1
  31. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/types.js +0 -11
  32. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/body.d.ts +0 -80
  33. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/body.d.ts.map +0 -1
  34. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/body.js +0 -111
  35. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/constants.d.ts +0 -5
  36. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/constants.d.ts.map +0 -1
  37. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/constants.js +0 -4
  38. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/headers.d.ts +0 -9
  39. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/headers.d.ts.map +0 -1
  40. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/headers.js +0 -5
  41. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/html.d.ts +0 -45
  42. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/html.d.ts.map +0 -1
  43. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/html.js +0 -122
  44. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/http-status.d.ts +0 -33
  45. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/http-status.d.ts.map +0 -1
  46. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/http-status.js +0 -5
  47. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/mime.d.ts +0 -71
  48. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/mime.d.ts.map +0 -1
  49. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/mime.js +0 -83
  50. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/types.d.ts +0 -75
  51. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/types.d.ts.map +0 -1
  52. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/types.js +0 -5
  53. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/url.d.ts +0 -30
  54. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/url.d.ts.map +0 -1
  55. package/esm/deps/jsr.io/@hono/hono/4.11.1/src/utils/url.js +0 -255
  56. package/esm/mod.d.ts +0 -5
  57. package/esm/mod.d.ts.map +0 -1
  58. package/esm/mod.js +0 -1
  59. package/esm/package.json +0 -3
@@ -1,327 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { HTTPException } from './http-exception.js';
3
- import { GET_MATCH_RESULT } from './request/constants.js';
4
- import { parseBody } from './utils/body.js';
5
- import { decodeURIComponent_, getQueryParam, getQueryParams, tryDecode } from './utils/url.js';
6
- const tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
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 = {};
40
- constructor(request, path = '/', matchResult = [[]]) {
41
- this.raw = request;
42
- this.path = path;
43
- this.#matchResult = matchResult;
44
- this.#validatedData = {};
45
- }
46
- param(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;
67
- }
68
- query(key) {
69
- return getQueryParam(this.url, key);
70
- }
71
- queries(key) {
72
- return getQueryParams(this.url, key);
73
- }
74
- header(name) {
75
- if (name) {
76
- return this.raw.headers.get(name) ?? undefined;
77
- }
78
- const headerData = {};
79
- this.raw.headers.forEach((value, key) => {
80
- headerData[key] = value;
81
- });
82
- return headerData;
83
- }
84
- async parseBody(options) {
85
- return (this.bodyCache.parsedBody ??= await parseBody(this, options));
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
- };
104
- /**
105
- * `.json()` can parse Request body of type `application/json`
106
- *
107
- * @see {@link https://hono.dev/docs/api/request#json}
108
- *
109
- * @example
110
- * ```ts
111
- * app.post('/entry', async (c) => {
112
- * const body = await c.req.json()
113
- * })
114
- * ```
115
- */
116
- json() {
117
- return this.#cachedBody('text').then((text) => JSON.parse(text));
118
- }
119
- /**
120
- * `.text()` can parse Request body of type `text/plain`
121
- *
122
- * @see {@link https://hono.dev/docs/api/request#text}
123
- *
124
- * @example
125
- * ```ts
126
- * app.post('/entry', async (c) => {
127
- * const body = await c.req.text()
128
- * })
129
- * ```
130
- */
131
- text() {
132
- return this.#cachedBody('text');
133
- }
134
- /**
135
- * `.arrayBuffer()` parse Request body as an `ArrayBuffer`
136
- *
137
- * @see {@link https://hono.dev/docs/api/request#arraybuffer}
138
- *
139
- * @example
140
- * ```ts
141
- * app.post('/entry', async (c) => {
142
- * const body = await c.req.arrayBuffer()
143
- * })
144
- * ```
145
- */
146
- arrayBuffer() {
147
- return this.#cachedBody('arrayBuffer');
148
- }
149
- /**
150
- * Parses the request body as a `Blob`.
151
- * @example
152
- * ```ts
153
- * app.post('/entry', async (c) => {
154
- * const body = await c.req.blob();
155
- * });
156
- * ```
157
- * @see https://hono.dev/docs/api/request#blob
158
- */
159
- blob() {
160
- return this.#cachedBody('blob');
161
- }
162
- /**
163
- * Parses the request body as `FormData`.
164
- * @example
165
- * ```ts
166
- * app.post('/entry', async (c) => {
167
- * const body = await c.req.formData();
168
- * });
169
- * ```
170
- * @see https://hono.dev/docs/api/request#formdata
171
- */
172
- formData() {
173
- return this.#cachedBody('formData');
174
- }
175
- /**
176
- * Adds validated data to the request.
177
- *
178
- * @param target - The target of the validation.
179
- * @param data - The validated data to add.
180
- */
181
- addValidatedData(target, data) {
182
- this.#validatedData[target] = data;
183
- }
184
- valid(target) {
185
- return this.#validatedData[target];
186
- }
187
- /**
188
- * `.url()` can get the request url strings.
189
- *
190
- * @see {@link https://hono.dev/docs/api/request#url}
191
- *
192
- * @example
193
- * ```ts
194
- * app.get('/about/me', (c) => {
195
- * const url = c.req.url // `http://localhost:8787/about/me`
196
- * ...
197
- * })
198
- * ```
199
- */
200
- get url() {
201
- return this.raw.url;
202
- }
203
- /**
204
- * `.method()` can get the method name of the request.
205
- *
206
- * @see {@link https://hono.dev/docs/api/request#method}
207
- *
208
- * @example
209
- * ```ts
210
- * app.get('/about/me', (c) => {
211
- * const method = c.req.method // `GET`
212
- * })
213
- * ```
214
- */
215
- get method() {
216
- return this.raw.method;
217
- }
218
- get [GET_MATCH_RESULT]() {
219
- return this.#matchResult;
220
- }
221
- /**
222
- * `.matchedRoutes()` can return a matched route in the handler
223
- *
224
- * @deprecated
225
- *
226
- * Use matchedRoutes helper defined in "hono/route" instead.
227
- *
228
- * @see {@link https://hono.dev/docs/api/request#matchedroutes}
229
- *
230
- * @example
231
- * ```ts
232
- * app.use('*', async function logger(c, next) {
233
- * await next()
234
- * c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
235
- * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
236
- * console.log(
237
- * method,
238
- * ' ',
239
- * path,
240
- * ' '.repeat(Math.max(10 - path.length, 0)),
241
- * name,
242
- * i === c.req.routeIndex ? '<- respond from here' : ''
243
- * )
244
- * })
245
- * })
246
- * ```
247
- */
248
- get matchedRoutes() {
249
- return this.#matchResult[0].map(([[, route]]) => route);
250
- }
251
- /**
252
- * `routePath()` can retrieve the path registered within the handler
253
- *
254
- * @deprecated
255
- *
256
- * Use routePath helper defined in "hono/route" instead.
257
- *
258
- * @see {@link https://hono.dev/docs/api/request#routepath}
259
- *
260
- * @example
261
- * ```ts
262
- * app.get('/posts/:id', (c) => {
263
- * return c.json({ path: c.req.routePath })
264
- * })
265
- * ```
266
- */
267
- get routePath() {
268
- return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
269
- }
270
- }
271
- /**
272
- * Clones a HonoRequest's underlying raw Request object.
273
- *
274
- * This utility handles both consumed and unconsumed request bodies:
275
- * - If the request body hasn't been consumed, it uses the native `clone()` method
276
- * - If the request body has been consumed, it reconstructs a new Request using cached body data
277
- *
278
- * This is particularly useful when you need to:
279
- * - Process the same request body multiple times
280
- * - Pass requests to external services after validation
281
- *
282
- * @param req - The HonoRequest object to clone
283
- * @returns A Promise that resolves to a new Request object with the same properties
284
- * @throws {HTTPException} If the request body was consumed directly via `req.raw`
285
- * without using HonoRequest methods (e.g., `req.json()`, `req.text()`), making it
286
- * impossible to reconstruct the body from cache
287
- *
288
- * @example
289
- * ```ts
290
- * // Clone after consuming the body (e.g., after validation)
291
- * app.post('/forward',
292
- * validator('json', (data) => data),
293
- * async (c) => {
294
- * const validated = c.req.valid('json')
295
- * // Body has been consumed, but cloneRawRequest still works
296
- * const clonedReq = await cloneRawRequest(c.req)
297
- * return fetch('http://backend-service.com', clonedReq)
298
- * }
299
- * )
300
- * ```
301
- */
302
- export const cloneRawRequest = async (req) => {
303
- if (!req.raw.bodyUsed) {
304
- return req.raw.clone();
305
- }
306
- const cacheKey = Object.keys(req.bodyCache)[0];
307
- if (!cacheKey) {
308
- throw new HTTPException(500, {
309
- message: 'Cannot clone request: body was already consumed and not cached. Please use HonoRequest methods (e.g., req.json(), req.text()) instead of consuming req.raw directly.',
310
- });
311
- }
312
- const requestInit = {
313
- body: await req[cacheKey](),
314
- cache: req.raw.cache,
315
- credentials: req.raw.credentials,
316
- headers: req.header(),
317
- integrity: req.raw.integrity,
318
- keepalive: req.raw.keepalive,
319
- method: req.method,
320
- mode: req.raw.mode,
321
- redirect: req.raw.redirect,
322
- referrer: req.raw.referrer,
323
- referrerPolicy: req.raw.referrerPolicy,
324
- signal: req.raw.signal,
325
- };
326
- return new Request(req.url, requestInit);
327
- };
@@ -1,98 +0,0 @@
1
- /**
2
- * @module
3
- * This module provides types definitions and variables for the routers.
4
- */
5
- /**
6
- * Constant representing all HTTP methods in uppercase.
7
- */
8
- export declare const METHOD_NAME_ALL: "ALL";
9
- /**
10
- * Constant representing all HTTP methods in lowercase.
11
- */
12
- export declare const METHOD_NAME_ALL_LOWERCASE: "all";
13
- /**
14
- * Array of supported HTTP methods.
15
- */
16
- export declare const METHODS: readonly ["get", "post", "put", "delete", "options", "patch"];
17
- /**
18
- * Error message indicating that a route cannot be added because the matcher is already built.
19
- */
20
- export declare const MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
21
- /**
22
- * Interface representing a router.
23
- *
24
- * @template T - The type of the handler.
25
- */
26
- export interface Router<T> {
27
- /**
28
- * The name of the router.
29
- */
30
- name: string;
31
- /**
32
- * Adds a route to the router.
33
- *
34
- * @param method - The HTTP method (e.g., 'get', 'post').
35
- * @param path - The path for the route.
36
- * @param handler - The handler for the route.
37
- */
38
- add(method: string, path: string, handler: T): void;
39
- /**
40
- * Matches a route based on the given method and path.
41
- *
42
- * @param method - The HTTP method (e.g., 'get', 'post').
43
- * @param path - The path to match.
44
- * @returns The result of the match.
45
- */
46
- match(method: string, path: string): Result<T>;
47
- }
48
- /**
49
- * Type representing a map of parameter indices.
50
- */
51
- export type ParamIndexMap = Record<string, number>;
52
- /**
53
- * Type representing a stash of parameters.
54
- */
55
- export type ParamStash = string[];
56
- /**
57
- * Type representing a map of parameters.
58
- */
59
- export type Params = Record<string, string>;
60
- /**
61
- * Type representing the result of a route match.
62
- *
63
- * The result can be in one of two formats:
64
- * 1. An array of handlers with their corresponding parameter index maps, followed by a parameter stash.
65
- * 2. An array of handlers with their corresponding parameter maps.
66
- *
67
- * Example:
68
- *
69
- * [[handler, paramIndexMap][], paramArray]
70
- * ```typescript
71
- * [
72
- * [
73
- * [middlewareA, {}], // '*'
74
- * [funcA, {'id': 0}], // '/user/:id/*'
75
- * [funcB, {'id': 0, 'action': 1}], // '/user/:id/:action'
76
- * ],
77
- * ['123', 'abc']
78
- * ]
79
- * ```
80
- *
81
- * [[handler, params][]]
82
- * ```typescript
83
- * [
84
- * [
85
- * [middlewareA, {}], // '*'
86
- * [funcA, {'id': '123'}], // '/user/:id/*'
87
- * [funcB, {'id': '123', 'action': 'abc'}], // '/user/:id/:action'
88
- * ]
89
- * ]
90
- * ```
91
- */
92
- export type Result<T> = [[T, ParamIndexMap][], ParamStash] | [[T, Params][]];
93
- /**
94
- * Error class representing an unsupported path error.
95
- */
96
- export declare class UnsupportedPathError extends Error {
97
- }
98
- //# sourceMappingURL=router.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@hono/hono/4.11.1/src/router.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe,EAAG,KAAc,CAAA;AAC7C;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAG,KAAc,CAAA;AACvD;;GAEG;AACH,eAAO,MAAM,OAAO,+DAAgE,CAAA;AACpF;;GAEG;AACH,eAAO,MAAM,gCAAgC,4DACc,CAAA;AAE3D;;;;GAIG;AACH,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;;;;;OAMG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAA;IAEnD;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;CAC/C;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAClD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,EAAE,CAAA;AACjC;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,EAAE,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAA;AAE5E;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;CAAG"}
@@ -1,25 +0,0 @@
1
- /**
2
- * @module
3
- * This module provides types definitions and variables for the routers.
4
- */
5
- /**
6
- * Constant representing all HTTP methods in uppercase.
7
- */
8
- export const METHOD_NAME_ALL = 'ALL';
9
- /**
10
- * Constant representing all HTTP methods in lowercase.
11
- */
12
- export const METHOD_NAME_ALL_LOWERCASE = 'all';
13
- /**
14
- * Array of supported HTTP methods.
15
- */
16
- export const METHODS = ['get', 'post', 'put', 'delete', 'options', 'patch'];
17
- /**
18
- * Error message indicating that a route cannot be added because the matcher is already built.
19
- */
20
- export const MESSAGE_MATCHER_IS_ALREADY_BUILT = 'Can not add a route since the matcher is already built.';
21
- /**
22
- * Error class representing an unsupported path error.
23
- */
24
- export class UnsupportedPathError extends Error {
25
- }