@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,410 +0,0 @@
1
- import { HonoRequest } from './request.js';
2
- import { HtmlEscapedCallbackPhase, resolveCallback } from './utils/html.js';
3
- export const TEXT_PLAIN = 'text/plain; charset=UTF-8';
4
- const setDefaultContentType = (contentType, headers) => {
5
- return {
6
- 'Content-Type': contentType,
7
- ...headers,
8
- };
9
- };
10
- export class Context {
11
- #rawRequest;
12
- #req;
13
- /**
14
- * `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
15
- *
16
- * @see {@link https://hono.dev/docs/api/context#env}
17
- *
18
- * @example
19
- * ```ts
20
- * // Environment object for Cloudflare Workers
21
- * app.get('*', async c => {
22
- * const counter = c.env.COUNTER
23
- * })
24
- * ```
25
- */
26
- env = {};
27
- #var;
28
- finalized = false;
29
- /**
30
- * `.error` can get the error object from the middleware if the Handler throws an error.
31
- *
32
- * @see {@link https://hono.dev/docs/api/context#error}
33
- *
34
- * @example
35
- * ```ts
36
- * app.use('*', async (c, next) => {
37
- * await next()
38
- * if (c.error) {
39
- * // do something...
40
- * }
41
- * })
42
- * ```
43
- */
44
- error;
45
- #status;
46
- #executionCtx;
47
- #res;
48
- #layout;
49
- #renderer;
50
- #notFoundHandler;
51
- #preparedHeaders;
52
- #matchResult;
53
- #path;
54
- /**
55
- * Creates an instance of the Context class.
56
- *
57
- * @param req - The Request object.
58
- * @param options - Optional configuration options for the context.
59
- */
60
- constructor(req, options) {
61
- this.#rawRequest = req;
62
- if (options) {
63
- this.#executionCtx = options.executionCtx;
64
- this.env = options.env;
65
- this.#notFoundHandler = options.notFoundHandler;
66
- this.#path = options.path;
67
- this.#matchResult = options.matchResult;
68
- }
69
- }
70
- /**
71
- * `.req` is the instance of {@link HonoRequest}.
72
- */
73
- get req() {
74
- this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
75
- return this.#req;
76
- }
77
- /**
78
- * @see {@link https://hono.dev/docs/api/context#event}
79
- * The FetchEvent associated with the current request.
80
- *
81
- * @throws Will throw an error if the context does not have a FetchEvent.
82
- */
83
- get event() {
84
- if (this.#executionCtx && 'respondWith' in this.#executionCtx) {
85
- return this.#executionCtx;
86
- }
87
- else {
88
- throw Error('This context has no FetchEvent');
89
- }
90
- }
91
- /**
92
- * @see {@link https://hono.dev/docs/api/context#executionctx}
93
- * The ExecutionContext associated with the current request.
94
- *
95
- * @throws Will throw an error if the context does not have an ExecutionContext.
96
- */
97
- get executionCtx() {
98
- if (this.#executionCtx) {
99
- return this.#executionCtx;
100
- }
101
- else {
102
- throw Error('This context has no ExecutionContext');
103
- }
104
- }
105
- /**
106
- * @see {@link https://hono.dev/docs/api/context#res}
107
- * The Response object for the current request.
108
- */
109
- get res() {
110
- return (this.#res ||= new Response(null, {
111
- headers: (this.#preparedHeaders ??= new Headers()),
112
- }));
113
- }
114
- /**
115
- * Sets the Response object for the current request.
116
- *
117
- * @param _res - The Response object to set.
118
- */
119
- set res(_res) {
120
- if (this.#res && _res) {
121
- _res = new Response(_res.body, _res);
122
- for (const [k, v] of this.#res.headers.entries()) {
123
- if (k === 'content-type') {
124
- continue;
125
- }
126
- if (k === 'set-cookie') {
127
- const cookies = this.#res.headers.getSetCookie();
128
- _res.headers.delete('set-cookie');
129
- for (const cookie of cookies) {
130
- _res.headers.append('set-cookie', cookie);
131
- }
132
- }
133
- else {
134
- _res.headers.set(k, v);
135
- }
136
- }
137
- }
138
- this.#res = _res;
139
- this.finalized = true;
140
- }
141
- /**
142
- * `.render()` can create a response within a layout.
143
- *
144
- * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
145
- *
146
- * @example
147
- * ```ts
148
- * app.get('/', (c) => {
149
- * return c.render('Hello!')
150
- * })
151
- * ```
152
- */
153
- render = (...args) => {
154
- this.#renderer ??= (content) => this.html(content);
155
- return this.#renderer(...args);
156
- };
157
- /**
158
- * Sets the layout for the response.
159
- *
160
- * @param layout - The layout to set.
161
- * @returns The layout function.
162
- */
163
- setLayout = (layout) => (this.#layout = layout);
164
- /**
165
- * Gets the current layout for the response.
166
- *
167
- * @returns The current layout function.
168
- */
169
- getLayout = () => this.#layout;
170
- /**
171
- * `.setRenderer()` can set the layout in the custom middleware.
172
- *
173
- * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
174
- *
175
- * @example
176
- * ```tsx
177
- * app.use('*', async (c, next) => {
178
- * c.setRenderer((content) => {
179
- * return c.html(
180
- * <html>
181
- * <body>
182
- * <p>{content}</p>
183
- * </body>
184
- * </html>
185
- * )
186
- * })
187
- * await next()
188
- * })
189
- * ```
190
- */
191
- setRenderer = (renderer) => {
192
- this.#renderer = renderer;
193
- };
194
- /**
195
- * `.header()` can set headers.
196
- *
197
- * @see {@link https://hono.dev/docs/api/context#header}
198
- *
199
- * @example
200
- * ```ts
201
- * app.get('/welcome', (c) => {
202
- * // Set headers
203
- * c.header('X-Message', 'Hello!')
204
- * c.header('Content-Type', 'text/plain')
205
- *
206
- * return c.body('Thank you for coming')
207
- * })
208
- * ```
209
- */
210
- header = (name, value, options) => {
211
- if (this.finalized) {
212
- this.#res = new Response(this.#res.body, this.#res);
213
- }
214
- const headers = this.#res ? this.#res.headers : (this.#preparedHeaders ??= new Headers());
215
- if (value === undefined) {
216
- headers.delete(name);
217
- }
218
- else if (options?.append) {
219
- headers.append(name, value);
220
- }
221
- else {
222
- headers.set(name, value);
223
- }
224
- };
225
- status = (status) => {
226
- this.#status = status;
227
- };
228
- /**
229
- * `.set()` can set the value specified by the key.
230
- *
231
- * @see {@link https://hono.dev/docs/api/context#set-get}
232
- *
233
- * @example
234
- * ```ts
235
- * app.use('*', async (c, next) => {
236
- * c.set('message', 'Hono is hot!!')
237
- * await next()
238
- * })
239
- * ```
240
- */
241
- set = (key, value) => {
242
- this.#var ??= new Map();
243
- this.#var.set(key, value);
244
- };
245
- /**
246
- * `.get()` can use the value specified by the key.
247
- *
248
- * @see {@link https://hono.dev/docs/api/context#set-get}
249
- *
250
- * @example
251
- * ```ts
252
- * app.get('/', (c) => {
253
- * const message = c.get('message')
254
- * return c.text(`The message is "${message}"`)
255
- * })
256
- * ```
257
- */
258
- get = (key) => {
259
- return this.#var ? this.#var.get(key) : undefined;
260
- };
261
- /**
262
- * `.var` can access the value of a variable.
263
- *
264
- * @see {@link https://hono.dev/docs/api/context#var}
265
- *
266
- * @example
267
- * ```ts
268
- * const result = c.var.client.oneMethod()
269
- * ```
270
- */
271
- // c.var.propName is a read-only
272
- get var() {
273
- if (!this.#var) {
274
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
275
- return {};
276
- }
277
- return Object.fromEntries(this.#var);
278
- }
279
- #newResponse(data, arg, headers) {
280
- const responseHeaders = this.#res
281
- ? new Headers(this.#res.headers)
282
- : (this.#preparedHeaders ?? new Headers());
283
- if (typeof arg === 'object' && 'headers' in arg) {
284
- const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
285
- for (const [key, value] of argHeaders) {
286
- if (key.toLowerCase() === 'set-cookie') {
287
- responseHeaders.append(key, value);
288
- }
289
- else {
290
- responseHeaders.set(key, value);
291
- }
292
- }
293
- }
294
- if (headers) {
295
- for (const [k, v] of Object.entries(headers)) {
296
- if (typeof v === 'string') {
297
- responseHeaders.set(k, v);
298
- }
299
- else {
300
- responseHeaders.delete(k);
301
- for (const v2 of v) {
302
- responseHeaders.append(k, v2);
303
- }
304
- }
305
- }
306
- }
307
- const status = typeof arg === 'number' ? arg : (arg?.status ?? this.#status);
308
- return new Response(data, { status, headers: responseHeaders });
309
- }
310
- newResponse = (...args) => this.#newResponse(...args);
311
- /**
312
- * `.body()` can return the HTTP response.
313
- * You can set headers with `.header()` and set HTTP status code with `.status`.
314
- * This can also be set in `.text()`, `.json()` and so on.
315
- *
316
- * @see {@link https://hono.dev/docs/api/context#body}
317
- *
318
- * @example
319
- * ```ts
320
- * app.get('/welcome', (c) => {
321
- * // Set headers
322
- * c.header('X-Message', 'Hello!')
323
- * c.header('Content-Type', 'text/plain')
324
- * // Set HTTP status code
325
- * c.status(201)
326
- *
327
- * // Return the response body
328
- * return c.body('Thank you for coming')
329
- * })
330
- * ```
331
- */
332
- body = (data, arg, headers) => this.#newResponse(data, arg, headers);
333
- /**
334
- * `.text()` can render text as `Content-Type:text/plain`.
335
- *
336
- * @see {@link https://hono.dev/docs/api/context#text}
337
- *
338
- * @example
339
- * ```ts
340
- * app.get('/say', (c) => {
341
- * return c.text('Hello!')
342
- * })
343
- * ```
344
- */
345
- text = (text, arg, headers) => {
346
- return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized
347
- ? new Response(text)
348
- : this.#newResponse(text, arg, setDefaultContentType(TEXT_PLAIN, headers));
349
- };
350
- /**
351
- * `.json()` can render JSON as `Content-Type:application/json`.
352
- *
353
- * @see {@link https://hono.dev/docs/api/context#json}
354
- *
355
- * @example
356
- * ```ts
357
- * app.get('/api', (c) => {
358
- * return c.json({ message: 'Hello!' })
359
- * })
360
- * ```
361
- */
362
- json = (object, arg, headers) => {
363
- return this.#newResponse(JSON.stringify(object), arg, setDefaultContentType('application/json', headers)) /* eslint-disable @typescript-eslint/no-explicit-any */;
364
- };
365
- html = (html, arg, headers) => {
366
- const res = (html) => this.#newResponse(html, arg, setDefaultContentType('text/html; charset=UTF-8', headers));
367
- return typeof html === 'object'
368
- ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res)
369
- : res(html);
370
- };
371
- /**
372
- * `.redirect()` can Redirect, default status code is 302.
373
- *
374
- * @see {@link https://hono.dev/docs/api/context#redirect}
375
- *
376
- * @example
377
- * ```ts
378
- * app.get('/redirect', (c) => {
379
- * return c.redirect('/')
380
- * })
381
- * app.get('/redirect-permanently', (c) => {
382
- * return c.redirect('/', 301)
383
- * })
384
- * ```
385
- */
386
- redirect = (location, status) => {
387
- const locationString = String(location);
388
- this.header('Location',
389
- // Multibyes should be encoded
390
- // eslint-disable-next-line no-control-regex
391
- !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString));
392
- return this.newResponse(null, status ?? 302);
393
- };
394
- /**
395
- * `.notFound()` can return the Not Found Response.
396
- *
397
- * @see {@link https://hono.dev/docs/api/context#notfound}
398
- *
399
- * @example
400
- * ```ts
401
- * app.get('/notfound', (c) => {
402
- * return c.notFound()
403
- * })
404
- * ```
405
- */
406
- notFound = () => {
407
- this.#notFoundHandler ??= () => new Response();
408
- return this.#notFoundHandler(this);
409
- };
410
- }
@@ -1,70 +0,0 @@
1
- /**
2
- * @module
3
- * WebSocket Helper for Hono.
4
- */
5
- import type { Context } from '../../context.js';
6
- import type { MiddlewareHandler, TypedResponse } from '../../types.js';
7
- import type { StatusCode } from '../../utils/http-status.js';
8
- /**
9
- * WebSocket Event Listeners type
10
- */
11
- export interface WSEvents<T = unknown> {
12
- onOpen?: (evt: Event, ws: WSContext<T>) => void;
13
- onMessage?: (evt: MessageEvent<WSMessageReceive>, ws: WSContext<T>) => void;
14
- onClose?: (evt: CloseEvent, ws: WSContext<T>) => void;
15
- onError?: (evt: Event, ws: WSContext<T>) => void;
16
- }
17
- /**
18
- * Upgrade WebSocket Type
19
- */
20
- export interface UpgradeWebSocket<T = unknown, U = any, _WSEvents = WSEvents<T>> {
21
- (createEvents: (c: Context) => _WSEvents | Promise<_WSEvents>, options?: U): MiddlewareHandler<any, string, {
22
- outputFormat: 'ws';
23
- }>;
24
- (c: Context, events: _WSEvents, options?: U): Promise<Response & TypedResponse<{}, StatusCode, 'ws'>>;
25
- }
26
- /**
27
- * ReadyState for WebSocket
28
- */
29
- export type WSReadyState = 0 | 1 | 2 | 3;
30
- /**
31
- * An argument for WSContext class
32
- */
33
- export interface WSContextInit<T = unknown> {
34
- send(data: string | ArrayBuffer | Uint8Array, options: SendOptions): void;
35
- close(code?: number, reason?: string): void;
36
- raw?: T;
37
- readyState: WSReadyState;
38
- url?: string | URL | null;
39
- protocol?: string | null;
40
- }
41
- /**
42
- * Options for sending message
43
- */
44
- export interface SendOptions {
45
- compress?: boolean;
46
- }
47
- /**
48
- * A context for controlling WebSockets
49
- */
50
- export declare class WSContext<T = unknown> {
51
- #private;
52
- constructor(init: WSContextInit<T>);
53
- send(source: string | ArrayBuffer | Uint8Array<ArrayBuffer>, options?: SendOptions): void;
54
- raw?: T;
55
- binaryType: BinaryType;
56
- get readyState(): WSReadyState;
57
- url: URL | null;
58
- protocol: string | null;
59
- close(code?: number, reason?: string): void;
60
- }
61
- export type WSMessageReceive = string | Blob | ArrayBufferLike;
62
- export declare const createWSMessageEvent: (source: WSMessageReceive) => MessageEvent<WSMessageReceive>;
63
- export interface WebSocketHelperDefineContext {
64
- }
65
- export type WebSocketHelperDefineHandler<T, U> = (c: Context, events: WSEvents<T>, options?: U) => Promise<Response | void> | Response | void;
66
- /**
67
- * Create a WebSocket adapter/helper
68
- */
69
- export declare const defineWebSocketHelper: <T = unknown, U = any>(handler: WebSocketHelperDefineHandler<T, U>) => UpgradeWebSocket<T, U>;
70
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/deps/jsr.io/@hono/hono/4.11.1/src/helper/websocket/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAE5D;;GAEG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,GAAG,OAAO;IACnC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IAC/C,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,CAAC,gBAAgB,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IAC3E,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IACrD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;CACjD;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,GAAG,EAAE,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC;IAC7E,CACE,YAAY,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,EAC5D,OAAO,CAAC,EAAE,CAAC,GACV,iBAAiB,CAClB,GAAG,EACH,MAAM,EACN;QACE,YAAY,EAAE,IAAI,CAAA;KACnB,CACF,CAAA;IACD,CACE,CAAC,EAAE,OAAO,EACV,MAAM,EAAE,SAAS,EACjB,OAAO,CAAC,EAAE,CAAC,GACV,OAAO,CAAC,QAAQ,GAAG,aAAa,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC,CAAA;CAC3D;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAExC;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;IACxC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAAA;IACzE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAE3C,GAAG,CAAC,EAAE,CAAC,CAAA;IACP,UAAU,EAAE,YAAY,CAAA;IACxB,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;GAEG;AACH,qBAAa,SAAS,CAAC,CAAC,GAAG,OAAO;;gBAEpB,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC;IAMlC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;IAGzF,GAAG,CAAC,EAAE,CAAC,CAAA;IACP,UAAU,EAAE,UAAU,CAAgB;IACtC,IAAI,UAAU,IAAI,YAAY,CAE7B;IACD,GAAG,EAAE,GAAG,GAAG,IAAI,CAAA;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAGrC;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,IAAI,GAAG,eAAe,CAAA;AAE9D,eAAO,MAAM,oBAAoB,GAAI,QAAQ,gBAAgB,KAAG,YAAY,CAAC,gBAAgB,CAI5F,CAAA;AAED,MAAM,WAAW,4BAA4B;CAAG;AAChD,MAAM,MAAM,4BAA4B,CAAC,CAAC,EAAE,CAAC,IAAI,CAC/C,CAAC,EAAE,OAAO,EACV,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,OAAO,CAAC,EAAE,CAAC,KACR,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,QAAQ,GAAG,IAAI,CAAA;AAE/C;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,GAAG,EACxD,SAAS,4BAA4B,CAAC,CAAC,EAAE,CAAC,CAAC,KAC1C,gBAAgB,CAAC,CAAC,EAAE,CAAC,CA2BvB,CAAA"}
@@ -1,62 +0,0 @@
1
- /**
2
- * @module
3
- * WebSocket Helper for Hono.
4
- */
5
- /**
6
- * A context for controlling WebSockets
7
- */
8
- export class WSContext {
9
- #init;
10
- constructor(init) {
11
- this.#init = init;
12
- this.raw = init.raw;
13
- this.url = init.url ? new URL(init.url) : null;
14
- this.protocol = init.protocol ?? null;
15
- }
16
- send(source, options) {
17
- this.#init.send(source, options ?? {});
18
- }
19
- raw;
20
- binaryType = 'arraybuffer';
21
- get readyState() {
22
- return this.#init.readyState;
23
- }
24
- url;
25
- protocol;
26
- close(code, reason) {
27
- this.#init.close(code, reason);
28
- }
29
- }
30
- export const createWSMessageEvent = (source) => {
31
- return new MessageEvent('message', {
32
- data: source,
33
- });
34
- };
35
- /**
36
- * Create a WebSocket adapter/helper
37
- */
38
- export const defineWebSocketHelper = (handler) => {
39
- return ((...args) => {
40
- if (typeof args[0] === 'function') {
41
- const [createEvents, options] = args;
42
- return async function upgradeWebSocket(c, next) {
43
- const events = await createEvents(c);
44
- const result = await handler(c, events, options);
45
- if (result) {
46
- return result;
47
- }
48
- await next();
49
- };
50
- }
51
- else {
52
- const [c, events, options] = args;
53
- return (async () => {
54
- const upgraded = await handler(c, events, options);
55
- if (!upgraded) {
56
- throw new Error('Failed to upgrade WebSocket');
57
- }
58
- return upgraded;
59
- })();
60
- }
61
- });
62
- };