@kerebron/extension-server-hono 0.4.27 → 0.4.29

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 (97) hide show
  1. package/esm/HonoYjsMemAdapter.d.ts +41 -0
  2. package/esm/HonoYjsMemAdapter.d.ts.map +1 -0
  3. package/esm/HonoYjsMemAdapter.js +204 -0
  4. package/esm/HonoYjsMemAdapter.js.map +1 -0
  5. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/compose.d.ts +15 -0
  6. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/compose.d.ts.map +1 -0
  7. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/compose.js +65 -0
  8. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/compose.js.map +1 -0
  9. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/context.d.ts +452 -0
  10. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/context.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/context.js +411 -0
  12. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/context.js.map +1 -0
  13. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/helper/websocket/index.d.ts +70 -0
  14. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/helper/websocket/index.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/helper/websocket/index.js +63 -0
  16. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/helper/websocket/index.js.map +1 -0
  17. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/hono-base.d.ts +221 -0
  18. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/hono-base.d.ts.map +1 -0
  19. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/hono-base.js +392 -0
  20. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/hono-base.js.map +1 -0
  21. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/http-exception.d.ts +60 -0
  22. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/http-exception.d.ts.map +1 -0
  23. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/http-exception.js +62 -0
  24. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/http-exception.js.map +1 -0
  25. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/request/constants.d.ts +2 -0
  26. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/request/constants.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/request/constants.js +2 -0
  28. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/request/constants.js.map +1 -0
  29. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/request.d.ts +314 -0
  30. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/request.d.ts.map +1 -0
  31. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/request.js +328 -0
  32. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/request.js.map +1 -0
  33. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/router.d.ts +98 -0
  34. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/router.d.ts.map +1 -0
  35. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/router.js +26 -0
  36. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/router.js.map +1 -0
  37. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/types.d.ts +574 -0
  38. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/types.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/types.js +12 -0
  40. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/types.js.map +1 -0
  41. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/body.d.ts +80 -0
  42. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/body.d.ts.map +1 -0
  43. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/body.js +112 -0
  44. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/body.js.map +1 -0
  45. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/constants.d.ts +5 -0
  46. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/constants.d.ts.map +1 -0
  47. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/constants.js +5 -0
  48. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/constants.js.map +1 -0
  49. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/headers.d.ts +9 -0
  50. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/headers.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/headers.js +6 -0
  52. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/headers.js.map +1 -0
  53. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/html.d.ts +45 -0
  54. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/html.d.ts.map +1 -0
  55. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/html.js +123 -0
  56. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/html.js.map +1 -0
  57. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/http-status.d.ts +33 -0
  58. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/http-status.d.ts.map +1 -0
  59. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/http-status.js +6 -0
  60. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/http-status.js.map +1 -0
  61. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/mime.d.ts +71 -0
  62. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/mime.d.ts.map +1 -0
  63. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/mime.js +84 -0
  64. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/mime.js.map +1 -0
  65. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/types.d.ts +75 -0
  66. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/types.d.ts.map +1 -0
  67. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/types.js +6 -0
  68. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/types.js.map +1 -0
  69. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/url.d.ts +30 -0
  70. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/url.d.ts.map +1 -0
  71. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/url.js +256 -0
  72. package/esm/deps/jsr.io/@hono/hono/4.11.3/src/utils/url.js.map +1 -0
  73. package/esm/mod.d.ts +5 -0
  74. package/esm/mod.d.ts.map +1 -0
  75. package/esm/mod.js +2 -0
  76. package/esm/mod.js.map +1 -0
  77. package/esm/package.json +3 -0
  78. package/package.json +5 -2
  79. package/src/HonoYjsMemAdapter.ts +264 -0
  80. package/src/deps/jsr.io/@hono/hono/4.11.3/src/compose.ts +73 -0
  81. package/src/deps/jsr.io/@hono/hono/4.11.3/src/context.ts +770 -0
  82. package/src/deps/jsr.io/@hono/hono/4.11.3/src/helper/websocket/index.ts +140 -0
  83. package/src/deps/jsr.io/@hono/hono/4.11.3/src/hono-base.ts +539 -0
  84. package/src/deps/jsr.io/@hono/hono/4.11.3/src/http-exception.ts +78 -0
  85. package/src/deps/jsr.io/@hono/hono/4.11.3/src/request/constants.ts +1 -0
  86. package/src/deps/jsr.io/@hono/hono/4.11.3/src/request.ts +487 -0
  87. package/src/deps/jsr.io/@hono/hono/4.11.3/src/router.ts +103 -0
  88. package/src/deps/jsr.io/@hono/hono/4.11.3/src/types.ts +2489 -0
  89. package/src/deps/jsr.io/@hono/hono/4.11.3/src/utils/body.ts +229 -0
  90. package/src/deps/jsr.io/@hono/hono/4.11.3/src/utils/constants.ts +4 -0
  91. package/src/deps/jsr.io/@hono/hono/4.11.3/src/utils/headers.ts +333 -0
  92. package/src/deps/jsr.io/@hono/hono/4.11.3/src/utils/html.ts +182 -0
  93. package/src/deps/jsr.io/@hono/hono/4.11.3/src/utils/http-status.ts +72 -0
  94. package/src/deps/jsr.io/@hono/hono/4.11.3/src/utils/mime.ts +96 -0
  95. package/src/deps/jsr.io/@hono/hono/4.11.3/src/utils/types.ts +116 -0
  96. package/src/deps/jsr.io/@hono/hono/4.11.3/src/utils/url.ts +310 -0
  97. package/src/mod.ts +5 -0
@@ -0,0 +1,310 @@
1
+ /**
2
+ * @module
3
+ * URL utility.
4
+ */
5
+
6
+ export type Pattern = readonly [string, string, RegExp | true] | '*'
7
+
8
+ export const splitPath = (path: string): string[] => {
9
+ const paths = path.split('/')
10
+ if (paths[0] === '') {
11
+ paths.shift()
12
+ }
13
+ return paths
14
+ }
15
+
16
+ export const splitRoutingPath = (routePath: string): string[] => {
17
+ const { groups, path } = extractGroupsFromPath(routePath)
18
+
19
+ const paths = splitPath(path)
20
+ return replaceGroupMarks(paths, groups)
21
+ }
22
+
23
+ const extractGroupsFromPath = (path: string): { groups: [string, string][]; path: string } => {
24
+ const groups: [string, string][] = []
25
+
26
+ path = path.replace(/\{[^}]+\}/g, (match, index) => {
27
+ const mark = `@${index}`
28
+ groups.push([mark, match])
29
+ return mark
30
+ })
31
+
32
+ return { groups, path }
33
+ }
34
+
35
+ const replaceGroupMarks = (paths: string[], groups: [string, string][]): string[] => {
36
+ for (let i = groups.length - 1; i >= 0; i--) {
37
+ const [mark] = groups[i]
38
+
39
+ for (let j = paths.length - 1; j >= 0; j--) {
40
+ if (paths[j].includes(mark)) {
41
+ paths[j] = paths[j].replace(mark, groups[i][1])
42
+ break
43
+ }
44
+ }
45
+ }
46
+
47
+ return paths
48
+ }
49
+
50
+ const patternCache: { [key: string]: Pattern } = {}
51
+ export const getPattern = (label: string, next?: string): Pattern | null => {
52
+ // * => wildcard
53
+ // :id{[0-9]+} => ([0-9]+)
54
+ // :id => (.+)
55
+
56
+ if (label === '*') {
57
+ return '*'
58
+ }
59
+
60
+ const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/)
61
+ if (match) {
62
+ const cacheKey = `${label}#${next}`
63
+ if (!patternCache[cacheKey]) {
64
+ if (match[2]) {
65
+ patternCache[cacheKey] =
66
+ next && next[0] !== ':' && next[0] !== '*'
67
+ ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)]
68
+ : [label, match[1], new RegExp(`^${match[2]}$`)]
69
+ } else {
70
+ patternCache[cacheKey] = [label, match[1], true]
71
+ }
72
+ }
73
+
74
+ return patternCache[cacheKey]
75
+ }
76
+
77
+ return null
78
+ }
79
+
80
+ type Decoder = (str: string) => string
81
+ export const tryDecode = (str: string, decoder: Decoder): string => {
82
+ try {
83
+ return decoder(str)
84
+ } catch {
85
+ return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
86
+ try {
87
+ return decoder(match)
88
+ } catch {
89
+ return match
90
+ }
91
+ })
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Try to apply decodeURI() to given string.
97
+ * If it fails, skip invalid percent encoding or invalid UTF-8 sequences, and apply decodeURI() to the rest as much as possible.
98
+ * @param str The string to decode.
99
+ * @returns The decoded string that sometimes contains undecodable percent encoding.
100
+ * @example
101
+ * tryDecodeURI('Hello%20World') // 'Hello World'
102
+ * tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
103
+ */
104
+ const tryDecodeURI = (str: string) => tryDecode(str, decodeURI)
105
+
106
+ export const getPath = (request: Request): string => {
107
+ const url = request.url
108
+ const start = url.indexOf('/', url.indexOf(':') + 4)
109
+ let i = start
110
+ for (; i < url.length; i++) {
111
+ const charCode = url.charCodeAt(i)
112
+ if (charCode === 37) {
113
+ // '%'
114
+ // If the path contains percent encoding, use `indexOf()` to find '?' and return the result immediately.
115
+ // Although this is a performance disadvantage, it is acceptable since we prefer cases that do not include percent encoding.
116
+ const queryIndex = url.indexOf('?', i)
117
+ const path = url.slice(start, queryIndex === -1 ? undefined : queryIndex)
118
+ return tryDecodeURI(path.includes('%25') ? path.replace(/%25/g, '%2525') : path)
119
+ } else if (charCode === 63) {
120
+ // '?'
121
+ break
122
+ }
123
+ }
124
+ return url.slice(start, i)
125
+ }
126
+
127
+ export const getQueryStrings = (url: string): string => {
128
+ const queryIndex = url.indexOf('?', 8)
129
+ return queryIndex === -1 ? '' : '?' + url.slice(queryIndex + 1)
130
+ }
131
+
132
+ export const getPathNoStrict = (request: Request): string => {
133
+ const result = getPath(request)
134
+
135
+ // if strict routing is false => `/hello/hey/` and `/hello/hey` are treated the same
136
+ return result.length > 1 && result.at(-1) === '/' ? result.slice(0, -1) : result
137
+ }
138
+
139
+ /**
140
+ * Merge paths.
141
+ * @param {string[]} ...paths - The paths to merge.
142
+ * @returns {string} The merged path.
143
+ * @example
144
+ * mergePath('/api', '/users') // '/api/users'
145
+ * mergePath('/api/', '/users') // '/api/users'
146
+ * mergePath('/api', '/') // '/api'
147
+ * mergePath('/api/', '/') // '/api/'
148
+ */
149
+ export const mergePath: (...paths: string[]) => string = (
150
+ base: string | undefined,
151
+ sub: string | undefined,
152
+ ...rest: string[]
153
+ ): string => {
154
+ if (rest.length) {
155
+ sub = mergePath(sub as string, ...rest)
156
+ }
157
+ return `${base?.[0] === '/' ? '' : '/'}${base}${
158
+ sub === '/' ? '' : `${base?.at(-1) === '/' ? '' : '/'}${sub?.[0] === '/' ? sub.slice(1) : sub}`
159
+ }`
160
+ }
161
+
162
+ export const checkOptionalParameter = (path: string): string[] | null => {
163
+ /*
164
+ If path is `/api/animals/:type?` it will return:
165
+ [`/api/animals`, `/api/animals/:type`]
166
+ in other cases it will return null
167
+ */
168
+
169
+ if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(':')) {
170
+ return null
171
+ }
172
+
173
+ const segments = path.split('/')
174
+ const results: string[] = []
175
+ let basePath = ''
176
+
177
+ segments.forEach((segment) => {
178
+ if (segment !== '' && !/\:/.test(segment)) {
179
+ basePath += '/' + segment
180
+ } else if (/\:/.test(segment)) {
181
+ if (/\?/.test(segment)) {
182
+ if (results.length === 0 && basePath === '') {
183
+ results.push('/')
184
+ } else {
185
+ results.push(basePath)
186
+ }
187
+ const optionalSegment = segment.replace('?', '')
188
+ basePath += '/' + optionalSegment
189
+ results.push(basePath)
190
+ } else {
191
+ basePath += '/' + segment
192
+ }
193
+ }
194
+ })
195
+
196
+ return results.filter((v, i, a) => a.indexOf(v) === i)
197
+ }
198
+
199
+ // Optimized
200
+ const _decodeURI = (value: string) => {
201
+ if (!/[%+]/.test(value)) {
202
+ return value
203
+ }
204
+ if (value.indexOf('+') !== -1) {
205
+ value = value.replace(/\+/g, ' ')
206
+ }
207
+ return value.indexOf('%') !== -1 ? tryDecode(value, decodeURIComponent_) : value
208
+ }
209
+
210
+ const _getQueryParam = (
211
+ url: string,
212
+ key?: string,
213
+ multiple?: boolean
214
+ ): string | undefined | Record<string, string> | string[] | Record<string, string[]> => {
215
+ let encoded
216
+
217
+ if (!multiple && key && !/[%+]/.test(key)) {
218
+ // optimized for unencoded key
219
+
220
+ let keyIndex = url.indexOf('?', 8)
221
+ if (keyIndex === -1) {
222
+ return undefined
223
+ }
224
+ if (!url.startsWith(key, keyIndex + 1)) {
225
+ keyIndex = url.indexOf(`&${key}`, keyIndex + 1)
226
+ }
227
+ while (keyIndex !== -1) {
228
+ const trailingKeyCode = url.charCodeAt(keyIndex + key.length + 1)
229
+ if (trailingKeyCode === 61) {
230
+ const valueIndex = keyIndex + key.length + 2
231
+ const endIndex = url.indexOf('&', valueIndex)
232
+ return _decodeURI(url.slice(valueIndex, endIndex === -1 ? undefined : endIndex))
233
+ } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
234
+ return ''
235
+ }
236
+ keyIndex = url.indexOf(`&${key}`, keyIndex + 1)
237
+ }
238
+
239
+ encoded = /[%+]/.test(url)
240
+ if (!encoded) {
241
+ return undefined
242
+ }
243
+ // fallback to default routine
244
+ }
245
+
246
+ const results: Record<string, string> | Record<string, string[]> = {}
247
+ encoded ??= /[%+]/.test(url)
248
+
249
+ let keyIndex = url.indexOf('?', 8)
250
+ while (keyIndex !== -1) {
251
+ const nextKeyIndex = url.indexOf('&', keyIndex + 1)
252
+ let valueIndex = url.indexOf('=', keyIndex)
253
+ if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
254
+ valueIndex = -1
255
+ }
256
+ let name = url.slice(
257
+ keyIndex + 1,
258
+ valueIndex === -1 ? (nextKeyIndex === -1 ? undefined : nextKeyIndex) : valueIndex
259
+ )
260
+ if (encoded) {
261
+ name = _decodeURI(name)
262
+ }
263
+
264
+ keyIndex = nextKeyIndex
265
+
266
+ if (name === '') {
267
+ continue
268
+ }
269
+
270
+ let value
271
+ if (valueIndex === -1) {
272
+ value = ''
273
+ } else {
274
+ value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? undefined : nextKeyIndex)
275
+ if (encoded) {
276
+ value = _decodeURI(value)
277
+ }
278
+ }
279
+
280
+ if (multiple) {
281
+ if (!(results[name] && Array.isArray(results[name]))) {
282
+ results[name] = []
283
+ }
284
+ ;(results[name] as string[]).push(value)
285
+ } else {
286
+ results[name] ??= value
287
+ }
288
+ }
289
+
290
+ return key ? results[key] : results
291
+ }
292
+
293
+ export const getQueryParam: (
294
+ url: string,
295
+ key?: string
296
+ ) => string | undefined | Record<string, string> = _getQueryParam as (
297
+ url: string,
298
+ key?: string
299
+ ) => string | undefined | Record<string, string>
300
+
301
+ export const getQueryParams = (
302
+ url: string,
303
+ key?: string
304
+ ): string[] | undefined | Record<string, string[]> => {
305
+ return _getQueryParam(url, key, true) as string[] | undefined | Record<string, string[]>
306
+ }
307
+
308
+ // `decodeURIComponent` is a long name.
309
+ // By making it a function, we can use it commonly when minified, reducing the amount of code.
310
+ export const decodeURIComponent_ = decodeURIComponent
package/src/mod.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { WSEvents } from './deps/jsr.io/@hono/hono/4.11.3/src/helper/websocket/index.js';
2
+
3
+ export interface HonoWsAdapter {
4
+ upgradeWebSocket(roomName: string): WSEvents<WebSocket>;
5
+ }