@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,221 +0,0 @@
1
- /**
2
- * @module
3
- * This module is the base module for the Hono object.
4
- */
5
- import { Context } from './context.js';
6
- import type { ExecutionContext } from './context.js';
7
- import type { Router } from './router.js';
8
- import type { Env, ErrorHandler, H, HandlerInterface, MergePath, MergeSchemaPath, MiddlewareHandlerInterface, NotFoundHandler, OnHandlerInterface, RouterRoute, Schema } from './types.js';
9
- type GetPath<E extends Env> = (request: Request, options?: {
10
- env?: E['Bindings'];
11
- }) => string;
12
- export type HonoOptions<E extends Env> = {
13
- /**
14
- * `strict` option specifies whether to distinguish whether the last path is a directory or not.
15
- *
16
- * @see {@link https://hono.dev/docs/api/hono#strict-mode}
17
- *
18
- * @default true
19
- */
20
- strict?: boolean;
21
- /**
22
- * `router` option specifies which router to use.
23
- *
24
- * @see {@link https://hono.dev/docs/api/hono#router-option}
25
- *
26
- * @example
27
- * ```ts
28
- * const app = new Hono({ router: new RegExpRouter() })
29
- * ```
30
- */
31
- router?: Router<[H, RouterRoute]>;
32
- /**
33
- * `getPath` can handle the host header value.
34
- *
35
- * @see {@link https://hono.dev/docs/api/routing#routing-with-host-header-value}
36
- *
37
- * @example
38
- * ```ts
39
- * const app = new Hono({
40
- * getPath: (req) =>
41
- * '/' + req.headers.get('host') + req.url.replace(/^https?:\/\/[^/]+(\/[^?]*)/, '$1'),
42
- * })
43
- *
44
- * app.get('/www1.example.com/hello', () => c.text('hello www1'))
45
- *
46
- * // A following request will match the route:
47
- * // new Request('http://www1.example.com/hello', {
48
- * // headers: { host: 'www1.example.com' },
49
- * // })
50
- * ```
51
- */
52
- getPath?: GetPath<E>;
53
- };
54
- type MountOptionHandler = (c: Context) => unknown;
55
- type MountReplaceRequest = (originalRequest: Request) => Request;
56
- type MountOptions = MountOptionHandler | {
57
- optionHandler?: MountOptionHandler;
58
- replaceRequest?: MountReplaceRequest | false;
59
- };
60
- declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/', CurrentPath extends string = BasePath> {
61
- #private;
62
- get: HandlerInterface<E, 'get', S, BasePath, CurrentPath>;
63
- post: HandlerInterface<E, 'post', S, BasePath, CurrentPath>;
64
- put: HandlerInterface<E, 'put', S, BasePath, CurrentPath>;
65
- delete: HandlerInterface<E, 'delete', S, BasePath, CurrentPath>;
66
- options: HandlerInterface<E, 'options', S, BasePath, CurrentPath>;
67
- patch: HandlerInterface<E, 'patch', S, BasePath, CurrentPath>;
68
- all: HandlerInterface<E, 'all', S, BasePath, CurrentPath>;
69
- on: OnHandlerInterface<E, S, BasePath>;
70
- use: MiddlewareHandlerInterface<E, S, BasePath>;
71
- router: Router<[H, RouterRoute]>;
72
- readonly getPath: GetPath<E>;
73
- private _basePath;
74
- routes: RouterRoute[];
75
- constructor(options?: HonoOptions<E>);
76
- private errorHandler;
77
- /**
78
- * `.route()` allows grouping other Hono instance in routes.
79
- *
80
- * @see {@link https://hono.dev/docs/api/routing#grouping}
81
- *
82
- * @param {string} path - base Path
83
- * @param {Hono} app - other Hono instance
84
- * @returns {Hono} routed Hono instance
85
- *
86
- * @example
87
- * ```ts
88
- * const app = new Hono()
89
- * const app2 = new Hono()
90
- *
91
- * app2.get("/user", (c) => c.text("user"))
92
- * app.route("/api", app2) // GET /api/user
93
- * ```
94
- */
95
- route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string, SubCurrentPath extends string>(path: SubPath, app: Hono<SubEnv, SubSchema, SubBasePath, SubCurrentPath>): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> | S, BasePath, CurrentPath>;
96
- /**
97
- * `.basePath()` allows base paths to be specified.
98
- *
99
- * @see {@link https://hono.dev/docs/api/routing#base-path}
100
- *
101
- * @param {string} path - base Path
102
- * @returns {Hono} changed Hono instance
103
- *
104
- * @example
105
- * ```ts
106
- * const api = new Hono().basePath('/api')
107
- * ```
108
- */
109
- basePath<SubPath extends string>(path: SubPath): Hono<E, S, MergePath<BasePath, SubPath>, MergePath<BasePath, SubPath>>;
110
- /**
111
- * `.onError()` handles an error and returns a customized Response.
112
- *
113
- * @see {@link https://hono.dev/docs/api/hono#error-handling}
114
- *
115
- * @param {ErrorHandler} handler - request Handler for error
116
- * @returns {Hono} changed Hono instance
117
- *
118
- * @example
119
- * ```ts
120
- * app.onError((err, c) => {
121
- * console.error(`${err}`)
122
- * return c.text('Custom Error Message', 500)
123
- * })
124
- * ```
125
- */
126
- onError: (handler: ErrorHandler<E>) => Hono<E, S, BasePath, CurrentPath>;
127
- /**
128
- * `.notFound()` allows you to customize a Not Found Response.
129
- *
130
- * @see {@link https://hono.dev/docs/api/hono#not-found}
131
- *
132
- * @param {NotFoundHandler} handler - request handler for not-found
133
- * @returns {Hono} changed Hono instance
134
- *
135
- * @example
136
- * ```ts
137
- * app.notFound((c) => {
138
- * return c.text('Custom 404 Message', 404)
139
- * })
140
- * ```
141
- */
142
- notFound: (handler: NotFoundHandler<E>) => Hono<E, S, BasePath, CurrentPath>;
143
- /**
144
- * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
145
- *
146
- * @see {@link https://hono.dev/docs/api/hono#mount}
147
- *
148
- * @param {string} path - base Path
149
- * @param {Function} applicationHandler - other Request Handler
150
- * @param {MountOptions} [options] - options of `.mount()`
151
- * @returns {Hono} mounted Hono instance
152
- *
153
- * @example
154
- * ```ts
155
- * import { Router as IttyRouter } from 'itty-router'
156
- * import { Hono } from 'hono'
157
- * // Create itty-router application
158
- * const ittyRouter = IttyRouter()
159
- * // GET /itty-router/hello
160
- * ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
161
- *
162
- * const app = new Hono()
163
- * app.mount('/itty-router', ittyRouter.handle)
164
- * ```
165
- *
166
- * @example
167
- * ```ts
168
- * const app = new Hono()
169
- * // Send the request to another application without modification.
170
- * app.mount('/app', anotherApp, {
171
- * replaceRequest: (req) => req,
172
- * })
173
- * ```
174
- */
175
- mount(path: string, applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>, options?: MountOptions): Hono<E, S, BasePath, CurrentPath>;
176
- /**
177
- * `.fetch()` will be entry point of your app.
178
- *
179
- * @see {@link https://hono.dev/docs/api/hono#fetch}
180
- *
181
- * @param {Request} request - request Object of request
182
- * @param {Env} Env - env Object
183
- * @param {ExecutionContext} - context of execution
184
- * @returns {Response | Promise<Response>} response of request
185
- *
186
- */
187
- fetch: (request: Request, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
188
- /**
189
- * `.request()` is a useful method for testing.
190
- * You can pass a URL or pathname to send a GET request.
191
- * app will return a Response object.
192
- * ```ts
193
- * test('GET /hello is ok', async () => {
194
- * const res = await app.request('/hello')
195
- * expect(res.status).toBe(200)
196
- * })
197
- * ```
198
- * @see https://hono.dev/docs/api/hono#request
199
- */
200
- request: (input: RequestInfo | URL, requestInit?: RequestInit, Env?: E["Bindings"] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
201
- /**
202
- * `.fire()` automatically adds a global fetch event listener.
203
- * This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
204
- * @deprecated
205
- * Use `fire` from `hono/service-worker` instead.
206
- * ```ts
207
- * import { Hono } from 'hono'
208
- * import { fire } from 'hono/service-worker'
209
- *
210
- * const app = new Hono()
211
- * // ...
212
- * fire(app)
213
- * ```
214
- * @see https://hono.dev/docs/api/hono#fire
215
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
216
- * @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
217
- */
218
- fire: () => void;
219
- }
220
- export { Hono as HonoBase };
221
- //# sourceMappingURL=hono-base.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hono-base.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@hono/hono/4.11.1/src/hono-base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EACV,GAAG,EACH,YAAY,EAEZ,CAAC,EACD,gBAAgB,EAChB,SAAS,EACT,eAAe,EAEf,0BAA0B,EAE1B,eAAe,EACf,kBAAkB,EAClB,WAAW,EACX,MAAM,EACP,MAAM,YAAY,CAAA;AAiBnB,KAAK,OAAO,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAA;CAAE,KAAK,MAAM,CAAA;AAE7F,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,GAAG,IAAI;IACvC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CA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CAAC,CAAC,CAAC,KAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,CAGtE;IAED;;;;;;;;;;;;;;OAcG;IACH,QAAQ,GAAI,SAAS,eAAe,CAAC,CAAC,CAAC,KAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,CAG1E;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,kBAAkB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,EACpF,OAAO,CAAC,EAAE,YAAY,GACrB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC;IAkIpC;;;;;;;;;;OAUG;IACH,KAAK,EAAE,CACL,OAAO,EAAE,OAAO,EAChB,GAAG,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,EACxB,YAAY,CAAC,EAAE,gBAAgB,KAC5B,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEhC;IAED;;;;;;;;;;;OAWG;IACH,OAAO,GACL,OAAO,WAAW,GAAG,GAAG,EACxB,cAAc,WAAW,EACzB,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,EACxB,eAAe,gBAAgB,KAC9B,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAa9B;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,QAAO,IAAI,CAMd;CACF;AAED,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,CAAA"}
@@ -1,391 +0,0 @@
1
- /**
2
- * @module
3
- * This module is the base module for the Hono object.
4
- */
5
- /* eslint-disable @typescript-eslint/no-explicit-any */
6
- import { compose } from './compose.js';
7
- import { Context } from './context.js';
8
- import { METHODS, METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE } from './router.js';
9
- import { COMPOSED_HANDLER } from './utils/constants.js';
10
- import { getPath, getPathNoStrict, mergePath } from './utils/url.js';
11
- const notFoundHandler = (c) => {
12
- return c.text('404 Not Found', 404);
13
- };
14
- const errorHandler = (err, c) => {
15
- if ('getResponse' in err) {
16
- const res = err.getResponse();
17
- return c.newResponse(res.body, res);
18
- }
19
- console.error(err);
20
- return c.text('Internal Server Error', 500);
21
- };
22
- class Hono {
23
- get;
24
- post;
25
- put;
26
- delete;
27
- options;
28
- patch;
29
- all;
30
- on;
31
- use;
32
- /*
33
- This class is like an abstract class and does not have a router.
34
- To use it, inherit the class and implement router in the constructor.
35
- */
36
- router;
37
- getPath;
38
- // Cannot use `#` because it requires visibility at JavaScript runtime.
39
- _basePath = '/';
40
- #path = '/';
41
- routes = [];
42
- constructor(options = {}) {
43
- // Implementation of app.get(...handlers[]) or app.get(path, ...handlers[])
44
- const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
45
- allMethods.forEach((method) => {
46
- this[method] = (args1, ...args) => {
47
- if (typeof args1 === 'string') {
48
- this.#path = args1;
49
- }
50
- else {
51
- this.#addRoute(method, this.#path, args1);
52
- }
53
- args.forEach((handler) => {
54
- this.#addRoute(method, this.#path, handler);
55
- });
56
- return this;
57
- };
58
- });
59
- // Implementation of app.on(method, path, ...handlers[])
60
- this.on = (method, path, ...handlers) => {
61
- for (const p of [path].flat()) {
62
- this.#path = p;
63
- for (const m of [method].flat()) {
64
- handlers.map((handler) => {
65
- this.#addRoute(m.toUpperCase(), this.#path, handler);
66
- });
67
- }
68
- }
69
- return this;
70
- };
71
- // Implementation of app.use(...handlers[]) or app.use(path, ...handlers[])
72
- this.use = (arg1, ...handlers) => {
73
- if (typeof arg1 === 'string') {
74
- this.#path = arg1;
75
- }
76
- else {
77
- this.#path = '*';
78
- handlers.unshift(arg1);
79
- }
80
- handlers.forEach((handler) => {
81
- this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
82
- });
83
- return this;
84
- };
85
- const { strict, ...optionsWithoutStrict } = options;
86
- Object.assign(this, optionsWithoutStrict);
87
- this.getPath = (strict ?? true) ? (options.getPath ?? getPath) : getPathNoStrict;
88
- }
89
- #clone() {
90
- const clone = new Hono({
91
- router: this.router,
92
- getPath: this.getPath,
93
- });
94
- clone.errorHandler = this.errorHandler;
95
- clone.#notFoundHandler = this.#notFoundHandler;
96
- clone.routes = this.routes;
97
- return clone;
98
- }
99
- #notFoundHandler = notFoundHandler;
100
- // Cannot use `#` because it requires visibility at JavaScript runtime.
101
- errorHandler = errorHandler;
102
- /**
103
- * `.route()` allows grouping other Hono instance in routes.
104
- *
105
- * @see {@link https://hono.dev/docs/api/routing#grouping}
106
- *
107
- * @param {string} path - base Path
108
- * @param {Hono} app - other Hono instance
109
- * @returns {Hono} routed Hono instance
110
- *
111
- * @example
112
- * ```ts
113
- * const app = new Hono()
114
- * const app2 = new Hono()
115
- *
116
- * app2.get("/user", (c) => c.text("user"))
117
- * app.route("/api", app2) // GET /api/user
118
- * ```
119
- */
120
- route(path, app) {
121
- const subApp = this.basePath(path);
122
- app.routes.map((r) => {
123
- let handler;
124
- if (app.errorHandler === errorHandler) {
125
- handler = r.handler;
126
- }
127
- else {
128
- handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
129
- handler[COMPOSED_HANDLER] = r.handler;
130
- }
131
- subApp.#addRoute(r.method, r.path, handler);
132
- });
133
- return this;
134
- }
135
- /**
136
- * `.basePath()` allows base paths to be specified.
137
- *
138
- * @see {@link https://hono.dev/docs/api/routing#base-path}
139
- *
140
- * @param {string} path - base Path
141
- * @returns {Hono} changed Hono instance
142
- *
143
- * @example
144
- * ```ts
145
- * const api = new Hono().basePath('/api')
146
- * ```
147
- */
148
- basePath(path) {
149
- const subApp = this.#clone();
150
- subApp._basePath = mergePath(this._basePath, path);
151
- return subApp;
152
- }
153
- /**
154
- * `.onError()` handles an error and returns a customized Response.
155
- *
156
- * @see {@link https://hono.dev/docs/api/hono#error-handling}
157
- *
158
- * @param {ErrorHandler} handler - request Handler for error
159
- * @returns {Hono} changed Hono instance
160
- *
161
- * @example
162
- * ```ts
163
- * app.onError((err, c) => {
164
- * console.error(`${err}`)
165
- * return c.text('Custom Error Message', 500)
166
- * })
167
- * ```
168
- */
169
- onError = (handler) => {
170
- this.errorHandler = handler;
171
- return this;
172
- };
173
- /**
174
- * `.notFound()` allows you to customize a Not Found Response.
175
- *
176
- * @see {@link https://hono.dev/docs/api/hono#not-found}
177
- *
178
- * @param {NotFoundHandler} handler - request handler for not-found
179
- * @returns {Hono} changed Hono instance
180
- *
181
- * @example
182
- * ```ts
183
- * app.notFound((c) => {
184
- * return c.text('Custom 404 Message', 404)
185
- * })
186
- * ```
187
- */
188
- notFound = (handler) => {
189
- this.#notFoundHandler = handler;
190
- return this;
191
- };
192
- /**
193
- * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
194
- *
195
- * @see {@link https://hono.dev/docs/api/hono#mount}
196
- *
197
- * @param {string} path - base Path
198
- * @param {Function} applicationHandler - other Request Handler
199
- * @param {MountOptions} [options] - options of `.mount()`
200
- * @returns {Hono} mounted Hono instance
201
- *
202
- * @example
203
- * ```ts
204
- * import { Router as IttyRouter } from 'itty-router'
205
- * import { Hono } from 'hono'
206
- * // Create itty-router application
207
- * const ittyRouter = IttyRouter()
208
- * // GET /itty-router/hello
209
- * ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
210
- *
211
- * const app = new Hono()
212
- * app.mount('/itty-router', ittyRouter.handle)
213
- * ```
214
- *
215
- * @example
216
- * ```ts
217
- * const app = new Hono()
218
- * // Send the request to another application without modification.
219
- * app.mount('/app', anotherApp, {
220
- * replaceRequest: (req) => req,
221
- * })
222
- * ```
223
- */
224
- mount(path, applicationHandler, options) {
225
- // handle options
226
- let replaceRequest;
227
- let optionHandler;
228
- if (options) {
229
- if (typeof options === 'function') {
230
- optionHandler = options;
231
- }
232
- else {
233
- optionHandler = options.optionHandler;
234
- if (options.replaceRequest === false) {
235
- replaceRequest = (request) => request;
236
- }
237
- else {
238
- replaceRequest = options.replaceRequest;
239
- }
240
- }
241
- }
242
- // prepare handlers for request
243
- const getOptions = optionHandler
244
- ? (c) => {
245
- const options = optionHandler(c);
246
- return Array.isArray(options) ? options : [options];
247
- }
248
- : (c) => {
249
- let executionContext = undefined;
250
- try {
251
- executionContext = c.executionCtx;
252
- }
253
- catch { } // Do nothing
254
- return [c.env, executionContext];
255
- };
256
- replaceRequest ||= (() => {
257
- const mergedPath = mergePath(this._basePath, path);
258
- const pathPrefixLength = mergedPath === '/' ? 0 : mergedPath.length;
259
- return (request) => {
260
- const url = new URL(request.url);
261
- url.pathname = url.pathname.slice(pathPrefixLength) || '/';
262
- return new Request(url, request);
263
- };
264
- })();
265
- const handler = async (c, next) => {
266
- const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
267
- if (res) {
268
- return res;
269
- }
270
- await next();
271
- };
272
- this.#addRoute(METHOD_NAME_ALL, mergePath(path, '*'), handler);
273
- return this;
274
- }
275
- #addRoute(method, path, handler) {
276
- method = method.toUpperCase();
277
- path = mergePath(this._basePath, path);
278
- const r = { basePath: this._basePath, path, method, handler };
279
- this.router.add(method, path, [handler, r]);
280
- this.routes.push(r);
281
- }
282
- #handleError(err, c) {
283
- if (err instanceof Error) {
284
- return this.errorHandler(err, c);
285
- }
286
- throw err;
287
- }
288
- #dispatch(request, executionCtx, env, method) {
289
- // Handle HEAD method
290
- if (method === 'HEAD') {
291
- return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, 'GET')))();
292
- }
293
- const path = this.getPath(request, { env });
294
- const matchResult = this.router.match(method, path);
295
- const c = new Context(request, {
296
- path,
297
- matchResult,
298
- env,
299
- executionCtx,
300
- notFoundHandler: this.#notFoundHandler,
301
- });
302
- // Do not `compose` if it has only one handler
303
- if (matchResult[0].length === 1) {
304
- let res;
305
- try {
306
- res = matchResult[0][0][0][0](c, async () => {
307
- c.res = await this.#notFoundHandler(c);
308
- });
309
- }
310
- catch (err) {
311
- return this.#handleError(err, c);
312
- }
313
- return res instanceof Promise
314
- ? res
315
- .then((resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c)))
316
- .catch((err) => this.#handleError(err, c))
317
- : (res ?? this.#notFoundHandler(c));
318
- }
319
- const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
320
- return (async () => {
321
- try {
322
- const context = await composed(c);
323
- if (!context.finalized) {
324
- throw new Error('Context is not finalized. Did you forget to return a Response object or `await next()`?');
325
- }
326
- return context.res;
327
- }
328
- catch (err) {
329
- return this.#handleError(err, c);
330
- }
331
- })();
332
- }
333
- /**
334
- * `.fetch()` will be entry point of your app.
335
- *
336
- * @see {@link https://hono.dev/docs/api/hono#fetch}
337
- *
338
- * @param {Request} request - request Object of request
339
- * @param {Env} Env - env Object
340
- * @param {ExecutionContext} - context of execution
341
- * @returns {Response | Promise<Response>} response of request
342
- *
343
- */
344
- fetch = (request, ...rest) => {
345
- return this.#dispatch(request, rest[1], rest[0], request.method);
346
- };
347
- /**
348
- * `.request()` is a useful method for testing.
349
- * You can pass a URL or pathname to send a GET request.
350
- * app will return a Response object.
351
- * ```ts
352
- * test('GET /hello is ok', async () => {
353
- * const res = await app.request('/hello')
354
- * expect(res.status).toBe(200)
355
- * })
356
- * ```
357
- * @see https://hono.dev/docs/api/hono#request
358
- */
359
- request = (input, requestInit, Env, executionCtx) => {
360
- if (input instanceof Request) {
361
- return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
362
- }
363
- input = input.toString();
364
- return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath('/', input)}`, requestInit), Env, executionCtx);
365
- };
366
- /**
367
- * `.fire()` automatically adds a global fetch event listener.
368
- * This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
369
- * @deprecated
370
- * Use `fire` from `hono/service-worker` instead.
371
- * ```ts
372
- * import { Hono } from 'hono'
373
- * import { fire } from 'hono/service-worker'
374
- *
375
- * const app = new Hono()
376
- * // ...
377
- * fire(app)
378
- * ```
379
- * @see https://hono.dev/docs/api/hono#fire
380
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
381
- * @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
382
- */
383
- fire = () => {
384
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
385
- // @ts-ignore
386
- addEventListener('fetch', (event) => {
387
- event.respondWith(this.#dispatch(event.request, event, undefined, event.request.method));
388
- });
389
- };
390
- }
391
- export { Hono as HonoBase };
@@ -1,60 +0,0 @@
1
- /**
2
- * @module
3
- * This module provides the `HTTPException` class.
4
- */
5
- import type { ContentfulStatusCode } from './utils/http-status.js';
6
- /**
7
- * Options for creating an `HTTPException`.
8
- * @property res - Optional response object to use.
9
- * @property message - Optional custom error message.
10
- * @property cause - Optional cause of the error.
11
- */
12
- type HTTPExceptionOptions = {
13
- res?: Response;
14
- message?: string;
15
- cause?: unknown;
16
- };
17
- /**
18
- * `HTTPException` must be used when a fatal error such as authentication failure occurs.
19
- *
20
- * @see {@link https://hono.dev/docs/api/exception}
21
- *
22
- * @param {StatusCode} status - status code of HTTPException
23
- * @param {HTTPExceptionOptions} options - options of HTTPException
24
- * @param {HTTPExceptionOptions["res"]} options.res - response of options of HTTPException
25
- * @param {HTTPExceptionOptions["message"]} options.message - message of options of HTTPException
26
- * @param {HTTPExceptionOptions["cause"]} options.cause - cause of options of HTTPException
27
- *
28
- * @example
29
- * ```ts
30
- * import { HTTPException } from 'hono/http-exception'
31
- *
32
- * // ...
33
- *
34
- * app.post('/auth', async (c, next) => {
35
- * // authentication
36
- * if (authorized === false) {
37
- * throw new HTTPException(401, { message: 'Custom error message' })
38
- * }
39
- * await next()
40
- * })
41
- * ```
42
- */
43
- export declare class HTTPException extends Error {
44
- readonly res?: Response;
45
- readonly status: ContentfulStatusCode;
46
- /**
47
- * Creates an instance of `HTTPException`.
48
- * @param status - HTTP status code for the exception. Defaults to 500.
49
- * @param options - Additional options for the exception.
50
- */
51
- constructor(status?: ContentfulStatusCode, options?: HTTPExceptionOptions);
52
- /**
53
- * Returns the response object associated with the exception.
54
- * If a response object is not provided, a new response is created with the error message and status code.
55
- * @returns The response object.
56
- */
57
- getResponse(): Response;
58
- }
59
- export {};
60
- //# sourceMappingURL=http-exception.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-exception.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@hono/hono/4.11.1/src/http-exception.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAElE;;;;;GAKG;AACH,KAAK,oBAAoB,GAAG;IAC1B,GAAG,CAAC,EAAE,QAAQ,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAA;IAErC;;;;OAIG;gBACS,MAAM,GAAE,oBAA0B,EAAE,OAAO,CAAC,EAAE,oBAAoB;IAM9E;;;;OAIG;IACH,WAAW,IAAI,QAAQ;CAYxB"}