@kerebron/extension-server-hono 0.4.4 → 0.4.6

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 (61) hide show
  1. package/esm/HonoYjsMemAdapter.d.ts +2 -1
  2. package/esm/HonoYjsMemAdapter.d.ts.map +1 -1
  3. package/esm/HonoYjsMemAdapter.js +1 -0
  4. package/esm/_dnt.polyfills.d.ts +7 -0
  5. package/esm/_dnt.polyfills.d.ts.map +1 -0
  6. package/esm/_dnt.polyfills.js +1 -0
  7. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/compose.d.ts +15 -0
  8. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/compose.d.ts.map +1 -0
  9. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/compose.js +64 -0
  10. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/context.d.ts +452 -0
  11. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/context.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/context.js +513 -0
  13. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.d.ts +70 -0
  14. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.js +95 -0
  16. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/hono-base.d.ts +221 -0
  17. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/hono-base.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/hono-base.js +498 -0
  19. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/http-exception.d.ts +60 -0
  20. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/http-exception.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/http-exception.js +71 -0
  22. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request/constants.d.ts +2 -0
  23. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request/constants.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request/constants.js +1 -0
  25. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request.d.ts +314 -0
  26. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request.js +370 -0
  28. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/router.d.ts +98 -0
  29. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/router.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/router.js +25 -0
  31. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/types.d.ts +563 -0
  32. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/types.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/types.js +11 -0
  34. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/body.d.ts +80 -0
  35. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/body.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/body.js +111 -0
  37. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/constants.d.ts +5 -0
  38. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/constants.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/constants.js +4 -0
  40. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/headers.d.ts +9 -0
  41. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/headers.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/headers.js +5 -0
  43. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/html.d.ts +45 -0
  44. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/html.d.ts.map +1 -0
  45. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/html.js +122 -0
  46. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/http-status.d.ts +33 -0
  47. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/http-status.d.ts.map +1 -0
  48. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/http-status.js +5 -0
  49. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/mime.d.ts +71 -0
  50. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/mime.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/mime.js +83 -0
  52. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/types.d.ts +75 -0
  53. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/types.d.ts.map +1 -0
  54. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/types.js +5 -0
  55. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/url.d.ts +30 -0
  56. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/url.d.ts.map +1 -0
  57. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/url.js +255 -0
  58. package/esm/mod.d.ts +2 -1
  59. package/esm/mod.d.ts.map +1 -1
  60. package/esm/mod.js +1 -1
  61. package/package.json +3 -1
@@ -0,0 +1,513 @@
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 _Context_instances, _Context_rawRequest, _Context_req, _Context_var, _Context_status, _Context_executionCtx, _Context_res, _Context_layout, _Context_renderer, _Context_notFoundHandler, _Context_preparedHeaders, _Context_matchResult, _Context_path, _Context_newResponse;
13
+ import { HonoRequest } from './request.js';
14
+ import { HtmlEscapedCallbackPhase, resolveCallback } from './utils/html.js';
15
+ export const TEXT_PLAIN = 'text/plain; charset=UTF-8';
16
+ const setDefaultContentType = (contentType, headers) => {
17
+ return {
18
+ 'Content-Type': contentType,
19
+ ...headers,
20
+ };
21
+ };
22
+ export class Context {
23
+ /**
24
+ * Creates an instance of the Context class.
25
+ *
26
+ * @param req - The Request object.
27
+ * @param options - Optional configuration options for the context.
28
+ */
29
+ constructor(req, options) {
30
+ _Context_instances.add(this);
31
+ _Context_rawRequest.set(this, void 0);
32
+ _Context_req.set(this, void 0);
33
+ /**
34
+ * `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
35
+ *
36
+ * @see {@link https://hono.dev/docs/api/context#env}
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * // Environment object for Cloudflare Workers
41
+ * app.get('*', async c => {
42
+ * const counter = c.env.COUNTER
43
+ * })
44
+ * ```
45
+ */
46
+ Object.defineProperty(this, "env", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: {}
51
+ });
52
+ _Context_var.set(this, void 0);
53
+ Object.defineProperty(this, "finalized", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: false
58
+ });
59
+ /**
60
+ * `.error` can get the error object from the middleware if the Handler throws an error.
61
+ *
62
+ * @see {@link https://hono.dev/docs/api/context#error}
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * app.use('*', async (c, next) => {
67
+ * await next()
68
+ * if (c.error) {
69
+ * // do something...
70
+ * }
71
+ * })
72
+ * ```
73
+ */
74
+ Object.defineProperty(this, "error", {
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true,
78
+ value: void 0
79
+ });
80
+ _Context_status.set(this, void 0);
81
+ _Context_executionCtx.set(this, void 0);
82
+ _Context_res.set(this, void 0);
83
+ _Context_layout.set(this, void 0);
84
+ _Context_renderer.set(this, void 0);
85
+ _Context_notFoundHandler.set(this, void 0);
86
+ _Context_preparedHeaders.set(this, void 0);
87
+ _Context_matchResult.set(this, void 0);
88
+ _Context_path.set(this, void 0);
89
+ /**
90
+ * `.render()` can create a response within a layout.
91
+ *
92
+ * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * app.get('/', (c) => {
97
+ * return c.render('Hello!')
98
+ * })
99
+ * ```
100
+ */
101
+ Object.defineProperty(this, "render", {
102
+ enumerable: true,
103
+ configurable: true,
104
+ writable: true,
105
+ value: (...args) => {
106
+ __classPrivateFieldSet(this, _Context_renderer, __classPrivateFieldGet(this, _Context_renderer, "f") ?? ((content) => this.html(content)), "f");
107
+ return __classPrivateFieldGet(this, _Context_renderer, "f").call(this, ...args);
108
+ }
109
+ });
110
+ /**
111
+ * Sets the layout for the response.
112
+ *
113
+ * @param layout - The layout to set.
114
+ * @returns The layout function.
115
+ */
116
+ Object.defineProperty(this, "setLayout", {
117
+ enumerable: true,
118
+ configurable: true,
119
+ writable: true,
120
+ value: (layout) => (__classPrivateFieldSet(this, _Context_layout, layout, "f"))
121
+ });
122
+ /**
123
+ * Gets the current layout for the response.
124
+ *
125
+ * @returns The current layout function.
126
+ */
127
+ Object.defineProperty(this, "getLayout", {
128
+ enumerable: true,
129
+ configurable: true,
130
+ writable: true,
131
+ value: () => __classPrivateFieldGet(this, _Context_layout, "f")
132
+ });
133
+ /**
134
+ * `.setRenderer()` can set the layout in the custom middleware.
135
+ *
136
+ * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
137
+ *
138
+ * @example
139
+ * ```tsx
140
+ * app.use('*', async (c, next) => {
141
+ * c.setRenderer((content) => {
142
+ * return c.html(
143
+ * <html>
144
+ * <body>
145
+ * <p>{content}</p>
146
+ * </body>
147
+ * </html>
148
+ * )
149
+ * })
150
+ * await next()
151
+ * })
152
+ * ```
153
+ */
154
+ Object.defineProperty(this, "setRenderer", {
155
+ enumerable: true,
156
+ configurable: true,
157
+ writable: true,
158
+ value: (renderer) => {
159
+ __classPrivateFieldSet(this, _Context_renderer, renderer, "f");
160
+ }
161
+ });
162
+ /**
163
+ * `.header()` can set headers.
164
+ *
165
+ * @see {@link https://hono.dev/docs/api/context#header}
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * app.get('/welcome', (c) => {
170
+ * // Set headers
171
+ * c.header('X-Message', 'Hello!')
172
+ * c.header('Content-Type', 'text/plain')
173
+ *
174
+ * return c.body('Thank you for coming')
175
+ * })
176
+ * ```
177
+ */
178
+ Object.defineProperty(this, "header", {
179
+ enumerable: true,
180
+ configurable: true,
181
+ writable: true,
182
+ value: (name, value, options) => {
183
+ if (this.finalized) {
184
+ __classPrivateFieldSet(this, _Context_res, new Response(__classPrivateFieldGet(this, _Context_res, "f").body, __classPrivateFieldGet(this, _Context_res, "f")), "f");
185
+ }
186
+ const headers = __classPrivateFieldGet(this, _Context_res, "f") ? __classPrivateFieldGet(this, _Context_res, "f").headers : (__classPrivateFieldSet(this, _Context_preparedHeaders, __classPrivateFieldGet(this, _Context_preparedHeaders, "f") ?? new Headers(), "f"));
187
+ if (value === undefined) {
188
+ headers.delete(name);
189
+ }
190
+ else if (options?.append) {
191
+ headers.append(name, value);
192
+ }
193
+ else {
194
+ headers.set(name, value);
195
+ }
196
+ }
197
+ });
198
+ Object.defineProperty(this, "status", {
199
+ enumerable: true,
200
+ configurable: true,
201
+ writable: true,
202
+ value: (status) => {
203
+ __classPrivateFieldSet(this, _Context_status, status, "f");
204
+ }
205
+ });
206
+ /**
207
+ * `.set()` can set the value specified by the key.
208
+ *
209
+ * @see {@link https://hono.dev/docs/api/context#set-get}
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * app.use('*', async (c, next) => {
214
+ * c.set('message', 'Hono is hot!!')
215
+ * await next()
216
+ * })
217
+ * ```
218
+ */
219
+ Object.defineProperty(this, "set", {
220
+ enumerable: true,
221
+ configurable: true,
222
+ writable: true,
223
+ value: (key, value) => {
224
+ __classPrivateFieldSet(this, _Context_var, __classPrivateFieldGet(this, _Context_var, "f") ?? new Map(), "f");
225
+ __classPrivateFieldGet(this, _Context_var, "f").set(key, value);
226
+ }
227
+ });
228
+ /**
229
+ * `.get()` can use 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.get('/', (c) => {
236
+ * const message = c.get('message')
237
+ * return c.text(`The message is "${message}"`)
238
+ * })
239
+ * ```
240
+ */
241
+ Object.defineProperty(this, "get", {
242
+ enumerable: true,
243
+ configurable: true,
244
+ writable: true,
245
+ value: (key) => {
246
+ return __classPrivateFieldGet(this, _Context_var, "f") ? __classPrivateFieldGet(this, _Context_var, "f").get(key) : undefined;
247
+ }
248
+ });
249
+ Object.defineProperty(this, "newResponse", {
250
+ enumerable: true,
251
+ configurable: true,
252
+ writable: true,
253
+ value: (...args) => __classPrivateFieldGet(this, _Context_instances, "m", _Context_newResponse).call(this, ...args)
254
+ });
255
+ /**
256
+ * `.body()` can return the HTTP response.
257
+ * You can set headers with `.header()` and set HTTP status code with `.status`.
258
+ * This can also be set in `.text()`, `.json()` and so on.
259
+ *
260
+ * @see {@link https://hono.dev/docs/api/context#body}
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * app.get('/welcome', (c) => {
265
+ * // Set headers
266
+ * c.header('X-Message', 'Hello!')
267
+ * c.header('Content-Type', 'text/plain')
268
+ * // Set HTTP status code
269
+ * c.status(201)
270
+ *
271
+ * // Return the response body
272
+ * return c.body('Thank you for coming')
273
+ * })
274
+ * ```
275
+ */
276
+ Object.defineProperty(this, "body", {
277
+ enumerable: true,
278
+ configurable: true,
279
+ writable: true,
280
+ value: (data, arg, headers) => __classPrivateFieldGet(this, _Context_instances, "m", _Context_newResponse).call(this, data, arg, headers)
281
+ });
282
+ /**
283
+ * `.text()` can render text as `Content-Type:text/plain`.
284
+ *
285
+ * @see {@link https://hono.dev/docs/api/context#text}
286
+ *
287
+ * @example
288
+ * ```ts
289
+ * app.get('/say', (c) => {
290
+ * return c.text('Hello!')
291
+ * })
292
+ * ```
293
+ */
294
+ Object.defineProperty(this, "text", {
295
+ enumerable: true,
296
+ configurable: true,
297
+ writable: true,
298
+ value: (text, arg, headers) => {
299
+ return !__classPrivateFieldGet(this, _Context_preparedHeaders, "f") && !__classPrivateFieldGet(this, _Context_status, "f") && !arg && !headers && !this.finalized
300
+ ? new Response(text)
301
+ : __classPrivateFieldGet(this, _Context_instances, "m", _Context_newResponse).call(this, text, arg, setDefaultContentType(TEXT_PLAIN, headers));
302
+ }
303
+ });
304
+ /**
305
+ * `.json()` can render JSON as `Content-Type:application/json`.
306
+ *
307
+ * @see {@link https://hono.dev/docs/api/context#json}
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * app.get('/api', (c) => {
312
+ * return c.json({ message: 'Hello!' })
313
+ * })
314
+ * ```
315
+ */
316
+ Object.defineProperty(this, "json", {
317
+ enumerable: true,
318
+ configurable: true,
319
+ writable: true,
320
+ value: (object, arg, headers) => {
321
+ return __classPrivateFieldGet(this, _Context_instances, "m", _Context_newResponse).call(this, JSON.stringify(object), arg, setDefaultContentType('application/json', headers)) /* eslint-disable @typescript-eslint/no-explicit-any */;
322
+ }
323
+ });
324
+ Object.defineProperty(this, "html", {
325
+ enumerable: true,
326
+ configurable: true,
327
+ writable: true,
328
+ value: (html, arg, headers) => {
329
+ const res = (html) => __classPrivateFieldGet(this, _Context_instances, "m", _Context_newResponse).call(this, html, arg, setDefaultContentType('text/html; charset=UTF-8', headers));
330
+ return typeof html === 'object'
331
+ ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res)
332
+ : res(html);
333
+ }
334
+ });
335
+ /**
336
+ * `.redirect()` can Redirect, default status code is 302.
337
+ *
338
+ * @see {@link https://hono.dev/docs/api/context#redirect}
339
+ *
340
+ * @example
341
+ * ```ts
342
+ * app.get('/redirect', (c) => {
343
+ * return c.redirect('/')
344
+ * })
345
+ * app.get('/redirect-permanently', (c) => {
346
+ * return c.redirect('/', 301)
347
+ * })
348
+ * ```
349
+ */
350
+ Object.defineProperty(this, "redirect", {
351
+ enumerable: true,
352
+ configurable: true,
353
+ writable: true,
354
+ value: (location, status) => {
355
+ const locationString = String(location);
356
+ this.header('Location',
357
+ // Multibyes should be encoded
358
+ // eslint-disable-next-line no-control-regex
359
+ !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString));
360
+ return this.newResponse(null, status ?? 302);
361
+ }
362
+ });
363
+ /**
364
+ * `.notFound()` can return the Not Found Response.
365
+ *
366
+ * @see {@link https://hono.dev/docs/api/context#notfound}
367
+ *
368
+ * @example
369
+ * ```ts
370
+ * app.get('/notfound', (c) => {
371
+ * return c.notFound()
372
+ * })
373
+ * ```
374
+ */
375
+ Object.defineProperty(this, "notFound", {
376
+ enumerable: true,
377
+ configurable: true,
378
+ writable: true,
379
+ value: () => {
380
+ __classPrivateFieldSet(this, _Context_notFoundHandler, __classPrivateFieldGet(this, _Context_notFoundHandler, "f") ?? (() => new Response()), "f");
381
+ return __classPrivateFieldGet(this, _Context_notFoundHandler, "f").call(this, this);
382
+ }
383
+ });
384
+ __classPrivateFieldSet(this, _Context_rawRequest, req, "f");
385
+ if (options) {
386
+ __classPrivateFieldSet(this, _Context_executionCtx, options.executionCtx, "f");
387
+ this.env = options.env;
388
+ __classPrivateFieldSet(this, _Context_notFoundHandler, options.notFoundHandler, "f");
389
+ __classPrivateFieldSet(this, _Context_path, options.path, "f");
390
+ __classPrivateFieldSet(this, _Context_matchResult, options.matchResult, "f");
391
+ }
392
+ }
393
+ /**
394
+ * `.req` is the instance of {@link HonoRequest}.
395
+ */
396
+ get req() {
397
+ __classPrivateFieldSet(this, _Context_req, __classPrivateFieldGet(this, _Context_req, "f") ?? new HonoRequest(__classPrivateFieldGet(this, _Context_rawRequest, "f"), __classPrivateFieldGet(this, _Context_path, "f"), __classPrivateFieldGet(this, _Context_matchResult, "f")), "f");
398
+ return __classPrivateFieldGet(this, _Context_req, "f");
399
+ }
400
+ /**
401
+ * @see {@link https://hono.dev/docs/api/context#event}
402
+ * The FetchEvent associated with the current request.
403
+ *
404
+ * @throws Will throw an error if the context does not have a FetchEvent.
405
+ */
406
+ get event() {
407
+ if (__classPrivateFieldGet(this, _Context_executionCtx, "f") && 'respondWith' in __classPrivateFieldGet(this, _Context_executionCtx, "f")) {
408
+ return __classPrivateFieldGet(this, _Context_executionCtx, "f");
409
+ }
410
+ else {
411
+ throw Error('This context has no FetchEvent');
412
+ }
413
+ }
414
+ /**
415
+ * @see {@link https://hono.dev/docs/api/context#executionctx}
416
+ * The ExecutionContext associated with the current request.
417
+ *
418
+ * @throws Will throw an error if the context does not have an ExecutionContext.
419
+ */
420
+ get executionCtx() {
421
+ if (__classPrivateFieldGet(this, _Context_executionCtx, "f")) {
422
+ return __classPrivateFieldGet(this, _Context_executionCtx, "f");
423
+ }
424
+ else {
425
+ throw Error('This context has no ExecutionContext');
426
+ }
427
+ }
428
+ /**
429
+ * @see {@link https://hono.dev/docs/api/context#res}
430
+ * The Response object for the current request.
431
+ */
432
+ get res() {
433
+ return (__classPrivateFieldSet(this, _Context_res, __classPrivateFieldGet(this, _Context_res, "f") || new Response(null, {
434
+ headers: (__classPrivateFieldSet(this, _Context_preparedHeaders, __classPrivateFieldGet(this, _Context_preparedHeaders, "f") ?? new Headers(), "f")),
435
+ }), "f"));
436
+ }
437
+ /**
438
+ * Sets the Response object for the current request.
439
+ *
440
+ * @param _res - The Response object to set.
441
+ */
442
+ set res(_res) {
443
+ if (__classPrivateFieldGet(this, _Context_res, "f") && _res) {
444
+ _res = new Response(_res.body, _res);
445
+ for (const [k, v] of __classPrivateFieldGet(this, _Context_res, "f").headers.entries()) {
446
+ if (k === 'content-type') {
447
+ continue;
448
+ }
449
+ if (k === 'set-cookie') {
450
+ const cookies = __classPrivateFieldGet(this, _Context_res, "f").headers.getSetCookie();
451
+ _res.headers.delete('set-cookie');
452
+ for (const cookie of cookies) {
453
+ _res.headers.append('set-cookie', cookie);
454
+ }
455
+ }
456
+ else {
457
+ _res.headers.set(k, v);
458
+ }
459
+ }
460
+ }
461
+ __classPrivateFieldSet(this, _Context_res, _res, "f");
462
+ this.finalized = true;
463
+ }
464
+ /**
465
+ * `.var` can access the value of a variable.
466
+ *
467
+ * @see {@link https://hono.dev/docs/api/context#var}
468
+ *
469
+ * @example
470
+ * ```ts
471
+ * const result = c.var.client.oneMethod()
472
+ * ```
473
+ */
474
+ // c.var.propName is a read-only
475
+ get var() {
476
+ if (!__classPrivateFieldGet(this, _Context_var, "f")) {
477
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
478
+ return {};
479
+ }
480
+ return Object.fromEntries(__classPrivateFieldGet(this, _Context_var, "f"));
481
+ }
482
+ }
483
+ _Context_rawRequest = new WeakMap(), _Context_req = new WeakMap(), _Context_var = new WeakMap(), _Context_status = new WeakMap(), _Context_executionCtx = new WeakMap(), _Context_res = new WeakMap(), _Context_layout = new WeakMap(), _Context_renderer = new WeakMap(), _Context_notFoundHandler = new WeakMap(), _Context_preparedHeaders = new WeakMap(), _Context_matchResult = new WeakMap(), _Context_path = new WeakMap(), _Context_instances = new WeakSet(), _Context_newResponse = function _Context_newResponse(data, arg, headers) {
484
+ const responseHeaders = __classPrivateFieldGet(this, _Context_res, "f")
485
+ ? new Headers(__classPrivateFieldGet(this, _Context_res, "f").headers)
486
+ : __classPrivateFieldGet(this, _Context_preparedHeaders, "f") ?? new Headers();
487
+ if (typeof arg === 'object' && 'headers' in arg) {
488
+ const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
489
+ for (const [key, value] of argHeaders) {
490
+ if (key.toLowerCase() === 'set-cookie') {
491
+ responseHeaders.append(key, value);
492
+ }
493
+ else {
494
+ responseHeaders.set(key, value);
495
+ }
496
+ }
497
+ }
498
+ if (headers) {
499
+ for (const [k, v] of Object.entries(headers)) {
500
+ if (typeof v === 'string') {
501
+ responseHeaders.set(k, v);
502
+ }
503
+ else {
504
+ responseHeaders.delete(k);
505
+ for (const v2 of v) {
506
+ responseHeaders.append(k, v2);
507
+ }
508
+ }
509
+ }
510
+ }
511
+ const status = typeof arg === 'number' ? arg : arg?.status ?? __classPrivateFieldGet(this, _Context_status, "f");
512
+ return new Response(data, { status, headers: responseHeaders });
513
+ };
@@ -0,0 +1,70 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/deps/jsr.io/@hono/hono/4.10.7/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,M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AO,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"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @module
3
+ * WebSocket Helper for Hono.
4
+ */
5
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
6
+ if (kind === "m") throw new TypeError("Private method is not writable");
7
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
8
+ 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");
9
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _WSContext_init;
17
+ /**
18
+ * A context for controlling WebSockets
19
+ */
20
+ export class WSContext {
21
+ constructor(init) {
22
+ _WSContext_init.set(this, void 0);
23
+ Object.defineProperty(this, "raw", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ Object.defineProperty(this, "binaryType", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: 'arraybuffer'
34
+ });
35
+ Object.defineProperty(this, "url", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ Object.defineProperty(this, "protocol", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: void 0
46
+ });
47
+ __classPrivateFieldSet(this, _WSContext_init, init, "f");
48
+ this.raw = init.raw;
49
+ this.url = init.url ? new URL(init.url) : null;
50
+ this.protocol = init.protocol ?? null;
51
+ }
52
+ send(source, options) {
53
+ __classPrivateFieldGet(this, _WSContext_init, "f").send(source, options ?? {});
54
+ }
55
+ get readyState() {
56
+ return __classPrivateFieldGet(this, _WSContext_init, "f").readyState;
57
+ }
58
+ close(code, reason) {
59
+ __classPrivateFieldGet(this, _WSContext_init, "f").close(code, reason);
60
+ }
61
+ }
62
+ _WSContext_init = new WeakMap();
63
+ export const createWSMessageEvent = (source) => {
64
+ return new MessageEvent('message', {
65
+ data: source,
66
+ });
67
+ };
68
+ /**
69
+ * Create a WebSocket adapter/helper
70
+ */
71
+ export const defineWebSocketHelper = (handler) => {
72
+ return ((...args) => {
73
+ if (typeof args[0] === 'function') {
74
+ const [createEvents, options] = args;
75
+ return async function upgradeWebSocket(c, next) {
76
+ const events = await createEvents(c);
77
+ const result = await handler(c, events, options);
78
+ if (result) {
79
+ return result;
80
+ }
81
+ await next();
82
+ };
83
+ }
84
+ else {
85
+ const [c, events, options] = args;
86
+ return (async () => {
87
+ const upgraded = await handler(c, events, options);
88
+ if (!upgraded) {
89
+ throw new Error('Failed to upgrade WebSocket');
90
+ }
91
+ return upgraded;
92
+ })();
93
+ }
94
+ });
95
+ };